open clicking the "linktomenu" icon, the dialog open, i see the loading animation, and then get an error-dialog saying

Error on retrieving data from module.
TypeError
elemname has no properties

I already did deactive the devel module to make sure we got no error output confusing the linktomenu plugin.
Checking the transfered data with wireshark I found we get the following result:

{ "menus": { "1": { "root": true, "mid": 1, "path": "", "title": "Navigation", "hasChildren": true }, "2": { "root": true, "mid": 2, "path": "", "title": "Primary links", "hasChildren": true } } }

When trying linktonode I also get an error:

Error on retrieving data from module.
SyntaxError
syntax error

haven't yet found the data we get as response here ...

any hints what's going wrong?

CommentFileSizeAuthor
#5 linktocontent_bugfix.tgz5.82 KBstborchert

Comments

stborchert’s picture

Checking the transfered data with wireshark I found we get the following result:
{ "menus": { "1": { "root": true, "mid": 1, "path": "", "title": "Navigation", "hasChildren": true }, "2": { "root": true, "mid": 2, "path": "", "title": "Primary links", "hasChildren": true } } }

This looks as it should.
Did you try version 5.x-1.4? Version 5.x-1.x-dev is quite old.

greetings,

Stefan

ray007’s picture

Yes, I did use version 1.4 - didn't even know there was a 1.x-dev version too ;-)

ray007’s picture

Update: the module doesn't work with jquery 1.1.2 - downgrading to 1.0.4 (as shipped with drupal 5.1) makes it work again.
Unfortunately I need a new jquery library for other stuff on my site ...

ray007’s picture

Update 2: jquery 1.0.4 makes linktomenu work, linktonode still gets the same error.

stborchert’s picture

Version: 5.x-1.x-dev » 5.x-1.4
Assigned: Unassigned » stborchert
StatusFileSize
new5.82 KB

Hi.
Argh, I don't know where these errors came from (it worked before I created the release).
Whatever, please try the attached files (or use the patch within the archive) and don't forget to empty the browser cache (you can call the js-files directly in your browser to reload them).

Hope this is working now (worked with jQuery 1.1.2 for me).

ray007’s picture

I'm sorry, but no luck so far. At least not with linktonode, linktomenu now also works with jquery 1.1.2.

stborchert’s picture

Hm, I tried with different systems and browsers and both worked fine :-[
What is your error message? Still "syntax error"?

ray007’s picture

yes, still syntax error.
and I still can't find an answer from the server with the protocol analyzer.
otoh, there are lines in the apache log suggesting a http 200 return code, which would mean 'all ok'.

maybe a timeout problem because I have too many nodes?
seems it's giving up after about 12 seconds ...

stborchert’s picture

Hm, strange. I tried with about 10.000 nodes and about 1.000 categories (created by devel.module) and never had any problems.
Could you please try this file: http://drupal.org/files/issues/ltc_1.html
(You have to edit it and insert the url of your drupal installation).

If you don't change "vocabulary-id" and submit the form you should see the results that are sent to the plugin the first time you open it. Perhaps its not well-formed.

ray007’s picture

In your html-file the vocabulary id is prefilled with '0', while the linktonode dialog seems to initialize this parameter with '-1'. In both cases I get an empty result.
Once I change that parameter to '1', I do get a result:

{ "categories": [ { "vid": "1", "tid": "1", "title": "Public Forums" } ], "nodes": { } }

other valid vocabulary ids work as well.

stborchert’s picture

In your html-file the vocabulary id is prefilled with '0', while the linktonode dialog seems to initialize this parameter with '-1'.

You're right. -1 is the initial param.

Once I change that parameter to '1', I do get a result:

Looks good.
Now the big question: where's the error?

    success: function(data){
      try {
        var results = eval('(' + data + ');');
        _clearNodeList();
        if ((obj == null) || ($(obj).get(0).value > -1)) {
          if (_fillDropdown(obj, results)) {
            window.resizeBy(0, 17);
          }
        }
        _fillNodelist(results);
      }
      catch (e) {
        alert('Error on retrieving data from module.\n' + e.name + '\n' + e.message);
      } 
      finally {
        $('#statusImg').hide();
      }

linktonode/functions.js

Try to replace this with

    success: function(data){
      var results = eval('(' + data + ');');
      _clearNodeList();
      if ((obj == null) || ($(obj).get(0).value > -1)) {
        if (_fillDropdown(obj, results)) {
          window.resizeBy(0, 17);
        }
      }
      _fillNodelist(results);
      $('#statusImg').hide();

Perhaps we now get a line number.

ray007’s picture

Hmm, that didn't really improve things.
Now the error message is just "Error: error".

The problem is the empty response which makes

  var results = eval('(' + data + ');');

in line 58 fail.

stborchert’s picture

On setting vocabulary-id to -1 (see comment #10) do you get an empty result or { "categories": { }, "nodes": { } }?
At least "categories" must contain an entry (the root vocabulary).

ray007’s picture

empty - nothing at all

ray007’s picture

a bit debugging tells me function linktocontent_node_get_data() doens't return.

I don't reach the end of the while ($nd = db_fetch_object($nodes)) { ... loop, but only checking the nid-results and not loading all the nodes does show a sane (but quite big) result.

Haven't yet tested it, but I assume changing _linktocontent_node_query_nodes() to directly get more node-properties instead of doing a node_load() for each node in the result set may help things ...

Or limit the size of the result set, or ...

stborchert’s picture

Component: Code: Javascript » Code

Hm, ok. How many (uncategorized) nodes do you have?

A quick hack could be changing linktocontent_node.module.
function _linktocontent_node_get_nodes(...) line 200:

  while ($node = db_fetch_object($nodes)) {
    if (!isset($types[$node->type])
      || ($types[$node->type] !== $node->type))
      continue;

    $obj = new StdClass;
    $obj->nid = $node->nid;
    $obj->title = $node->title;
    $obj->date = format_date($node->changed, 'small');
    $obj->author = $node->name;
    $obj->type = $node->type;
    $obj->href = url('node/' . $node->nid);
    $obj->orig_href = 'node/' . $obj->nid;
    $results[$obj->orig_href] = $obj;
  } // while

and function _linktocontent_node_query_nodes($tid) line 250 to

$sql = 'SELECT DISTINCT(n.nid), n.sticky, n.title, n.created, u.name, tn.tid FROM {node} n INNER JOIN users u ON u.uid = n.uid ';

It loads the data directly from the database (unfortuantely without running load-hooks from other modules). I couldn't test it yet but it should work.

Btw., linktonode/jscripts/dropdown.js has a small additional bug. Change lines 35-40 to:

  // add event handler
  $(select).change(function() {
    _removeDescendant($(this).parent());
    _clearNodeList();
    loadCategories($(this));
  });

Otherwise nothing happens if you select a category.

hope this works,

Stefan

ray007’s picture

How many nodes? Didn't count them but a rough estimate from printing out the node-ids in the loop I'd say it's a 4 digit number ...

Will try to test your fix a bit later today.

ray007’s picture

Well, with your changes we're a step further now:

The call for linktonodes now returns with a result, the category selection box is filled, but unfortunately it didn't return any nodes.

After modifying the $sql sting on line 250 to also select n.type I now do get nodes in the result.

It's still unresponsive because I have too many nodes, I probably need a pager.

Note 1: I've been told one should enter the fields to select in a query in the same order as they are in the table for better performance. If this is true the query string on line 250 should be a bit re-ordered.

Note 2: Probably related to my many nodes - changing the category selection box to some value does _nothing_ here ... no change of selection, no ajax request, nothing.

Note 3: maybe it would make sense to also have a select box for the type of the node?

stborchert’s picture

The call for linktonodes now returns with a result, the category selection box is filled, but unfortunately it didn't return any nodes.
After modifying the $sql sting on line 250 to also select n.type I now do get nodes in the result.

Argh, forgot this.

It's still unresponsive because I have too many nodes, I probably need a pager.

Is planed for 6.x (http://rikrikrik.com/jquery/pager/ -> I modified it once to work with browsers history).

Note 1: I've been told one should enter the fields to select in a query in the same order as they are in the table for better performance. If this is true the query string on line 250 should be a bit re-ordered.

Did you try this? Makes sense (at least a little).

Note 2: Probably related to my many nodes - changing the category selection box to some value does _nothing_ here ... no change of selection, no ajax request, nothing.

Did you change linktonode/jscripts/dropdown.js as suggested in comment 16 (don't forget to clear browser cache or cal the file directly in browser)?

35:  // add event handler
36:  $(select).change(function() {
37:    _removeDescendant($(this).parent());
38:    _clearNodeList();
39:    loadCategories($(this));
40:  });

linktonode/jscripts/dropdown.js #35

Note 3: maybe it would make sense to also have a select box for the type of the node?

I plan to add a table filter. So you can filter for name, author, date, etc.
Probably grouping by type (typename as heading + collapsible rows) would make things easier?!

Uh, a lot of work :-)

ray007’s picture

Uh, yeah, sorry, had forgotten the js-file.

After that change things now work, though a bit surprising:
Choosing a vocabulary gives me the names of the terms in it in the document selection area ... is this as planned?
Selecting a term in the select box then gives the correct selection, un-selecting the term again (and having the vocabulary still selected) brings up again the selection of all nodes.

And the main point about paging is not some nice jquery magic for the display, but to only return a limited result set and get the next page with a new ajax request.

I'll try to take a stab at it if I find time, currently I still get the browser warning about unresponsive script, so it's not yet at a stage where a user can use it on my site.

Note: in the medium term it may make sense to not create select-statements in the module, but use views and the views argument api?
Note 2: I guess your fixes to the javascript and the changed sql query warrant a new release (or maybe just cvs checkin). Haven't yet checked if you already did since some ****** cvs admin made some monster commit on drupal.org so I can't the what modules have changed.

Many thanks for your help and the great work your doing here!

stborchert’s picture

After that change things now work, though a bit surprising:
Choosing a vocabulary gives me the names of the terms in it in the document selection area ... is this as planned?

If you've checked "term" on admin/settings/linktocontent/linktocontent_node. Otherwise its an error.
All content type you've selected (terms, pages, stories, etc.) should be shown (don't know which order).

And the main point about paging is not some nice jquery magic for the display, but to only return a limited result set and get the next page with a new ajax request.

You're right. That would reduce the load time remarkable.

Note: in the medium term it may make sense to not create select-statements in the module, but use views and the views argument api?

This is on my ToDo-list for 6.x. With the new version of drupal you can define the output type of a page (JSON!) so we can build a view and send it as JSON directly to the plugin. Then we get paging for free :-)

Note 2: I guess your fixes to the javascript and the changed sql query warrant a new release (or maybe just cvs checkin).

Haven't done this yet but will do today.

Haven't yet checked if you already did since some ****** cvs admin made some monster commit on drupal.org so I can't the what modules have changed.

Guess this was Derek (dww) removing the version string from all info-files ;-)

ray007’s picture

If you've checked "term" on admin/settings/linktocontent/linktocontent_node. Otherwise its an error.
All content type you've selected (terms, pages, stories, etc.) should be shown (don't know which order).

Ok, I had been wondering about "Term" on that settings page since I didn't have a content type "Term", but unchecking "Term" there now gives me an empty selection once I select a vocabulary.
Wishlist: all nodes tagged with a term in this vocabulary?

This is on my ToDo-list for 6.x. With the new version of drupal you can define the output type of a page (JSON!) so we can build a view and send it as JSON directly to the plugin. Then we get paging for free :-)

Maybe drupal 6 (or the views module for drupal 6) will have a json plugin for views, but this is possible today. I.e. the KML and the georss modules return their special xml format for view with those types.
But it's not even necessary that the views-module return the json string, we could use views to just get the list of nodes (with fields) and then format the json string ...

A quick search on drupal.org brings me to http://drupal.org/project/views_json ;-)

stborchert’s picture

Status: Active » Fixed

Commited to cvs and created a new release (hope I did not forget anything).

..[snip]..

I see... I see some new feature requests coming... :-)

Two weeks from now my final exams are completed and after that I'll have more time to code.

stborchert’s picture

Status: Fixed » Closed (fixed)