Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
OnClose Event For Dialog boxes
27/06/2009
22:33
Avatar
tropotek
Member
Members
Forum Posts: 4
Member Since:
28/06/2009
sp_UserOfflineSmall Offline

First of all, thanks for a great piece of software…

After hours of trying I have been unable to find a common onClose event or similar for the dialog boxes (edit/view/add). I am trying to implement TinyMCE and so far I have had promising results.

However if I cancel or close the dialog box I have no event to hide TinyMce before the layer is hidden which in turn crashes TinyMce.

I have used the navGrid option events for initialising and hiding TinyMCE if a full edit/add has taken place, it works fine. But TinyMCE crashes if the textarea element is hidden before it is unregistered with the TinyMCE object.

A good article on the issue can be found at: http://blog.mirthlab.com/2008/.....to-a-page/

Maybe there could be a call for a new event in the navGrid (onHide() or onClose()?

I have tried:

//    $("#cData, .jqmClose:parent").bind('click', function (e) {
//        alert('Hiding Now!');
//    });

Any suggestions would be appreciated.

29/06/2009
03:03
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

Try

jQuery(".ui-jqdialog-titlebar-close").bind('click',function(){

// do something here

// if you use jqModal to close the modal you need

hideModal("#editmod"+gridid, {jqm:true});

// where gridid is your grid id and hideModal is a function from grid common

});

Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

30/06/2009
02:14
Avatar
tropotek
Member
Members
Forum Posts: 4
Member Since:
28/06/2009
sp_UserOfflineSmall Offline

Thanks for the tip Tony, but it didn't achieve the desired result. To get this to work you would have to add the code to the `afterShowForm` event so the dialog box exists first.

However I have had a play with the source code and it may be something you can add to the project. If we modify the hideModel() function a little like the following code. There could be better parameters passed to onClose if any,  but I will leave that up to you:

var hideModal = function (selector,o) {
    o = jQuery.extend({jqm : true, gb :''}, o || {});
    if(o.onClose) {
        o.onClose(selector, o);
    }

    if (jQuery.fn.jqm && o.jqm === true) {
        jQuery(selector).attr(”aria-hidden”,”true”).jqmHide();
    } else {
        if(o.gb != '') {
            try {jQuery(”.jqgrid-overlay”,o.gb).hide();} catch (e){}
        }
        jQuery(selector).hide().attr(”aria-hidden”,”true”);
    }
};

In the grid.formedit.js we can define the onClose functions in the dialog objects:

    searchGrid : function (p) {
            ….
            onInitializeSearch: null,
            onClose: null,
            closeAfterSearch : false,
            ….

    editGridRow : function(rowid, p){
            ….
            afterclickPgButtons: null,
            onClose: null,
            editData : {},
            ….

Then on all calls to the hideModel() function we send the onclose function:

    hideModal(”#”+IDs.themodal,{gb:”#gbox_”+gID,jqm:p.jqModal,onClose: p.onClose});

This way you can add the onClose event to an edit/add/view/search dialog box and it will be called whenever someone closes it.

If you can add this to the src files then we have a nice way to implement TinyMCE and I would be more than happy to write a short tutorial on how to implement it.

On another issue I have implemented the ajaxFileUplode as per your suggestions in the forum and I can say it is possible, and works great.

30/06/2009
07:00
Avatar
tropotek
Member
Members
Forum Posts: 4
Member Since:
28/06/2009
sp_UserOfflineSmall Offline

I have spent the day trying to get TinyMce to work and found some more things that may be of intrest.

An event like onShow would also help in the base system, Mainly for the view dialog as there is no hooks that I could find to modify the data that is shown.

Using the method outlined in the previous post I added an onShow event after the viewModal() functions are called. This was helpful so I could run jquery on elements in the view dialog.

A major issue I found is, that the view and edit dialog boxes are two seperate dialog instances but they have duplicate id values on the data. This creates havoc when you are looking for a form element by id and receive a td element because you viewed the data before editing the data.

However I added to this line in the view code (around line 870:grid.fomedit.js):

$(”td:eq(”+(cp-1)+”)”,trdata[0]).append(”<span style='position:absolute;float:left'>”+tmp+”</span>”).attr(”id”, 'v_' + nm);

Unfortunatly this stops the elements updating when using the next and previous buttons.

So adding the following into fillData() makes it work:

              function fillData(rowid,obj){
                var nm, hc,cnt=0,tmp, opt;
                $('#'+rowid+' td',obj.grid.bDiv).each( function(i) {
                    nm = 'v_' + obj.p.colModel[i].name;
                    ...

Just keep in mind it can be bad prictice to have multiple id values in any web app.

So at the end of it all, to implement TinyMCE I added an array of fields that I want the editor to attach to:

var mceList = ['comment'];

Then in the edit/add options objects I put somthing like this:

{
          width: 600,
          reloadAfterSubmit: false,
          closeAfterEdit: true,
          afterShowForm: function (form) {
              jQuery('#pData, #nData').hide();
              // Initalise MCE fields
              for (y=0; y < mceList.length; y++) {
                  tinyMCE.execCommand('mceAddControl', false, mceList[y]);
              }
          },
          onclickSubmit : function(eparams) {
              var retarr = {};
              // Grab the MCE editor content for posting
              for (y=0; y < mceList.length; y++) {
                  if (tinyMCE.getInstanceById(mceList[y])) {
                      eval('retarr.' + mceList[y] + ' = tinyMCE.getInstanceById(mceList[y]).getContent()');
                  }
              }
              return retarr;
          },
          onClose: function(sel, o) {  // <– NEW CALL
              // Clean up MCE before hide
              for (y=0; y < mceList.length; y++) {
                if (tinyMCE.getInstanceById(mceList[y])) {
                    tinyMCE.execCommand('mceFocus', false, mceList[y]);                   
                    tinyMCE.execCommand('mceRemoveControl', false, mceList[y]);
                }
              }
          },
          afterSubmit: function (response, postData) {
              return [true, ''];
          }
   
        }, // edit options

With these couple of additions, TinyMCE can be inserted without changing any of its base code. And hopefully if the onClose event is added no changes to the grid codebase would be required either.

Hope this info is useful.

Cheers

Mick

02/07/2009
02:45
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello Mick,

First of all thank you very much for your excelent additions and recommendations.

Also the onClose event will be included in the 3.5 release, moreover I will do some tricky condition like this

var hideModal = function (selector,o) {
    o = jQuery.extend({jqm : true, gb :''}, o || {});
    if(o.onClose) {
       var oncret =  o.onClose(selector, o);

if (typeof oncret == 'boolean'  && !oncret ) return;
    }

    if (jQuery.fn.jqm && o.jqm === true) {
        jQuery(selector).attr(”aria-hidden”,”true”).jqmHide();
    } else {
        if(o.gb != '') {
            try {jQuery(”.jqgrid-overlay”,o.gb).hide();} catch (e){}
        }
        jQuery(selector).hide().attr(”aria-hidden”,”true”);
    }
};

This way we can control if the dilog should be closed under some condition. If this event does not retun any value the dialog will be closed, but if the event return false the dialog will not be closed.

Regarding the equal id's in the edit and view form you are abolutley right. WIll make the needed changes.

Thanks again

Best Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

02/07/2009
18:02
Avatar
tropotek
Member
Members
Forum Posts: 4
Member Since:
28/06/2009
sp_UserOfflineSmall Offline

That's fantastic news.

I look forward to the 3.5 release.

08/07/2009
05:37
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

I have added this. You can download it from the site.

Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
74 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information