Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Tree, beforenodedrop, cancel if db update fails

  1. #1

    Default Tree, beforenodedrop, cancel if db update fails

    I've been searching forums and found a lot of posts about similar problems, even "wars" about asynchronous versus synchronous, etc.. but haven't found an final answer I expect (hope).

    Case is that I have an tree that uses "beforenodedrop" event to fire updating of database with an ASP script... part of the code that does that is:
    Code:
    listeners: {'beforenodedrop': function(e) {
    			Ext.Ajax.request({
    				url: 'page.asp',
    				success: function (result, request) { 
    					if (result.responseText != 'OK') {
    						Ext.MessageBox.alert('Failed', result.responseText)
    						e.cancel=true;
    					}
    				},
    ... problem is that Ajax.request is asynchronous so even if ASP page returns error, tree still gets updated. I'm aware of the solution to use a e.cancel before Ajax.request and then handle moving of node manually, but it really does not seem as elegant solution to me. Too much lines of code that seem unnecessary when framework already took care of 99% of work and now I have to do it all over again manually instead that framework waitds for the result of Ajax.request?

    Is there any other solution to problem above?

  2. #2
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,890

    Default

    You have got to use a drag proxy which just carries information. Do the Ajax call, and update the UI according to the return status. Where's the problem.

    The DnD just triggerss events, it doesn't really do that much. It just tells you that the user has performed a gesture. Once you know what they want to do, then go and do that operation, and update the UI.

  3. #3

    Default

    I forgot to mention that I'm a noob in javascript. I do have experiance in VB and similar. Maybe I'm misunderstanding that "doing it manually" is a big deal. But I can't find out how to do it simply, in a line or two of code. Also I failed to find any example online. Can you help?

  4. #4
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,890

    Default

    What do you want to do? It all depends on how you want to update the UI.

    I never find that it's just a DOM node being inserted from some place to someplace else.

    A Drag gesture drags some kind of "image" of information being moved, and the drop gesture is a command to do something.

    But the way the UI gets updated after that is pretty much up to your own design. It can't be automated.

  5. #5

    Default

    I want to do whatever I cancel with 'e.cancel' in my code. I guess it *is* just a DOM node being moved somewhere else because "information" is in SQL database together with majority of the code of this app that I'm trying to upgrade with some improoved usability features...

    Problem is that I see there can be 2, or 3 different actions in a node drop event:
    1) APPEND: Source node is appended to target node
    2) REORDER: Node is moved inside the same tree (parent stays the same)
    3) MOVE + REORDER + DELETE: same as append + same as reorder + delete from old parent

    I have no problems doing it in MS SQL but in javascript and ext js it looks too complex for me. Appending is simple with "append" but 2) and 3) require quite a few lines of code if I understand it correctly.

  6. #6
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,890

    Default

    It's never going to be easy. You've got to work on it.

  7. #7

    Default

    I started playing with ext last week to speed up development of some parts of my ASP/SQL app. I was looking for a framework that has widgets that are easy to implement. If described action needs pages of code in javascript I'm afraid ext is not for me.

    I do understand that I cannot avoid js programming when developing complete apps in js with a lot of widgets communicating with each other, but I use 99% of ASP and SQL code. Widgets are basicaly stand alone modules here, islands for themselves in my ASP app. A tree here, an autocomplete dropdown there, maybe a grid too, and that's it. I do not want to reprogram an action in js that I have already done in SQL. It seems that stand-alone widgets like NlsTree Pro are better choice for me.

    ... but to explore one last option before I give up... is it possible to make Ajax.Request synchronous somehow? So TreePanel waits for the result from it?

  8. #8
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,890

    Default

    You are never going to be able to find some magic javascript library you are just going to be able to wave your hands at and get a drag/drop enabled web app out of it.

  9. #9

    Default

    I have to disagree with you on this one. Maybe it looks like that from your point of view, and my guess is that it is a view of javascript developer developing apps in javascript. But from the point of view of an ASP/PHP/SQL developer "magic" widgets do exist and are frequently used.

    Last night I installed NlsTree Pro and managed to get drag&drop functionality in my tree in half of hour without any js programming. I'll search for similar standalone widgets for grid and autocomplete dropdown and my problems are solved.

  10. #10

    Default solved

    and update thanx to my colleague that pointed this thread to me:
    http://extjs.com/forum/showthread.php?t=7376

    ...that has a link to solution here:
    http://extjs.com/forum/showthread.php?t=21681

    In short, solution is in ext-base.js extender by hendricd which (among other things) extends functionality of Ajax.request with an option "async" which you can set to "false". This has returned Ext from my recycle bin at the last moment.

    Back to first thread where was a long (repeated) discussion about Sync and Async... really interesting reading and I agree with the most... 99% of time Async is the way to go and you're doing something wrong if you're trying to go Sync... but there is that 1% or 5% where Sync is is the way to go. Like this example of mine... there is not a single line of javascript on my ASP/SQL page except this Tree widget. Dropping a node fires ASP/SQL script to reorder records in a database. It is crucial to keep on-screen tree and records in database in complete sync! So, there is apsolutely no benefit for me to do e.cancel and then reprogram dropping of the node in javascript instead of simple Sync request where Tree waits for the result of Ajax.request. It is just more work and code and bandwidth to achieve exactly the same action.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •