Hugo Madureira wrote:
> Beware as the Form.serialize function behaves differently than the
> submit function.
>   
This solution works _great_ for me - but I'm sure there is room for 
improvement. This is within the context of the symfony framework. The 
related database objects often have inherent dependencies - no surprise 
there. By allowing the user to add a required dependent 
object(related_module) from the context of the primary object/module, 
and not requiring him or her to go to a different window or tab to 
accomplish this, I'm able to maintain continuity, lessening user 
confusion (thank goodness!). Once the response from the post returns, I 
add that info to the select for that related module in the current form.

   var calling_document;
   var module;
   var related_module;
   
   function add_related_object(module_p, related_module_p)
   {
       module = module_p;
       related_module = related_module_p;
       calling_document = document;
  
       var opt = {
            method: 'get',
            on404: function(t) {
                alert('Error 404: location "' + t.statusText + '" was 
not found.');
            },
            // Handle other errors
            onFailure: function(t) {
                alert('Error ' + t.status + ' -- ' + t.statusText);
            }
        }
       
        var url_text = "/index.php/" + related_module + "/create?pwc=1";
       
           Dialog.confirm({url: url_text, options: opt},
                          {windowParameters: {className: "dialog", 
width: 518, height: 660 },
                          okLabel: "Save",
                          ok: post_response});
   }

   function post_response()
   {
       var win = Windows.focusedWindow;
      
       var data = Form.serialize(win.getId());

       var select_id = module + "[" + related_module + "_id]";
       var opt = {
          method: 'post',
          postBody: data,
          onSuccess: function(originalRequest) {
            add_option_to_select(originalRequest.responseText, select_id);
            //the post will return the contents to be added to the 
appropriate select in the form "value:text"
            Dialog.closeInfo();
           },
            on404: function(t) {
                alert('Error 404: location "' + t.statusText + '" was 
not found.');
            },
            // Handle other errors
            onFailure: function(t) {
                alert('Error ' + t.status + ' -- ' + t.statusText);
            }
       }
   
       var url_text = "/index.php/" + related_module + "/create?pwc=1";
       new Ajax.Request(url_text, opt);
   } 

    function add_option_to_select(new_option, select_element_id)
    {
      var option_elements = new_option.split(":");
      original_select = calling_document.getElementById(select_element_id);
      original_select.options[original_select.options.length] = new 
Option(option_elements[1], option_elements[0], false, true);
    }

>   

_______________________________________________
Javawin mailing list
[email protected]
http://mail.xilinus.com/mailman/listinfo/javawin_xilinus.com

Reply via email to