Chaning the OnInvokeAction with a custom view

200 views
Skip to first unread message

Josh

unread,
Apr 22, 2009, 7:16:40 AM4/22/09
to JMesa
Im working almost exclusively with Ajax tables and its possible to
have more than one open at a time, thus far JMesa has worked
flawlessly but now i have a table that I need to define a seperate
OnInvokeAction.

To do this I made a new View for the special table, and changed the
HtmlSnippet initJavascriptLimit() method to produce the following:

<script type="text/javascript" >
jQuery.jmesa.addTableFacade('contact-breakdown-table');
jQuery.jmesa.setMaxRowsToLimit('contact-breakdown-
table','20');
jQuery.jmesa.setPageToLimit('contact-breakdown-table','1');
jQuery.jmesa.setOnInvokeAction('contact-breakdown-
table','onReportInvokeAction');
jQuery.jmesa.setOnInvokeExportAction('contact-breakdown-
table','onReportInvokeExportAction');
</script>

Instead of the default which would be:

<script type="text/javascript" >
jQuery.jmesa.addTableFacade('contact-breakdown-table');
jQuery.jmesa.setMaxRowsToLimit('contact-breakdown-
table','20');
jQuery.jmesa.setPageToLimit('contact-breakdown-table','1');
jQuery.jmesa.setOnInvokeAction('contact-breakdown-
table','onInvokeAction');
jQuery.jmesa.setOnInvokeExportAction('contact-breakdown-
table','onInvokeExportAction');
</script>

Unfortunately, when I click on the table, it's still running
onInvokeAction instead of my new onReportInvokeAction


Am i missing something? Or is there something else i can do to debug?

Jeff Johnston

unread,
Apr 22, 2009, 8:07:15 AM4/22/09
to jm...@googlegroups.com
The way you would do something different per table is by using the id parameter that is passed to the onInvokeAction() method. You can also do something different per table action by looking at the action parameter.

http://code.google.com/p/jmesa/wiki/Javascript


You can change the name of the invoke actions, but only at a global level in your preferences file.

http://code.google.com/p/jmesa/wiki/Preferences
html.onInvokeAction=onInvokeAction
html.onInvokeExportAction=onInvokeExportAction

-Jeff Johnston

Josh

unread,
Apr 22, 2009, 9:27:11 AM4/22/09
to JMesa
I was affriad you were going to say that. Guess my invoke action will
just have to get a little messy.

Thanks for the quick reply Jeff.

On Apr 22, 1:07 pm, Jeff Johnston <jeff.johnston...@gmail.com> wrote:
> The way you would do something different per table is by using the id
> parameter that is passed to the onInvokeAction() method. You can also do
> something different per table action by looking at the action parameter.
>
> http://code.google.com/p/jmesa/wiki/Javascript
>
> You can change the name of the invoke actions, but only at a global level in
> your preferences file.
>
> http://code.google.com/p/jmesa/wiki/Preferences
> html.onInvokeAction=onInvokeAction
> html.onInvokeExportAction=onInvokeExportAction
>
> -Jeff Johnston
>

bcg

unread,
Apr 23, 2009, 8:48:19 AM4/23/09
to JMesa
Jeff, what would you think about making this work? It would actually
be fairly simple and also backwards compatible.

For example, this is what the onclick for one of the sorts looks like
for one of my tables:

jQuery.jmesa.addSortToLimit
('PC_7_2000000028LK30I0MLLM7G10M4_AssetClassesTable','2','description','asc');inventoryTableAction
('PC_7_2000000028LK30I0MLLM7G10M4_AssetClassesTable', 'sort')

if instead of calling "inventoryTableAction" directly, we simply used
"jQuery.jmesa.onInvokeAction" instead, Josh's example would work
fine. If we wanted to make it really convenient we could add
something to the table facade for setting the function names on a per-
table basis and modify initJavascriptLimit accordingly.

What do you think?

Jeff Johnston

unread,
Apr 23, 2009, 10:28:43 PM4/23/09
to JMesa
I'm not sure what you meant by "If instead of calling
"inventoryTableAction" directly, we simply used
"jQuery.jmesa.onInvokeAction" instead, Josh's example would work
fine."

I do remember us talking a few months ago about (optionally) declaring
the onInvokeAction on the TableFacade. I think it would be a good
improvement. I remember one of the challenges was figuring out how to
get those settings cleaning down to the view classes that need them.
Right now it is easy to just pull them from the preferences....

-Jeff Johnston

bcg

unread,
Apr 25, 2009, 11:17:57 AM4/25/09
to JMesa
In jquery.jmesa.js, this method is exists:

onInvokeAction : function (id, action) {
var tableFacade = this.getTableFacade(id);
var f = window[tableFacade.onInvokeAction];
if ($.isFunction(f) !== true) {
throw tableFacade.onInvokeAction + ' is not a global
function!';
} else {
f(id, action);
}
},

Calling this method should invoke whatever invoke action is set on the
table facade. There is also a version for exports. If we change the
renders to call this method instead of the global method directly, we
can avoid the trouble of getting those settings down to the view
classes. That would make Josh's example above work properly.

Another solution could be to make the Preferences object writable, so
that after the table facade is instantiated, there could be methods to
override preferences for individual tables at run time. Seems easy to
do with a decorator (only one method to implement on the Preferences
interface). Actually Josh, the more I think about it that might be
your easiest solution in the short term.

Jeff Johnston

unread,
Apr 27, 2009, 10:14:18 AM4/27/09
to jm...@googlegroups.com
Thanks for reminding me about those settings!

I see what you are saying...if methods called jQuery.jmesa.onInvokeAction() directly then only the view would have to worry about setting what the actual onInvokeAction is. I think that is a good improvement in general!

Setting what the actual onInvokeAction is other than at the global level would still require a lot of cut and paste, in a custom view, of the HtmlSnippets.initJavascriptLimit() method. That makes your other idea of making the Preferences overridable on a per table basis very appealing, and brilliant! It would actually be more of a proxy though as the new Object would control access to the underlying Preferences, which would be perfect. So that means that the TableFacade would create a PreferencesProxy and there would be two new methods on the TableFacade to set the onInvokeAction() and onInvokeExportAction().

So neither help Josh right now, but both would be big improvements to the API and really not all that much work.

-Jeff Johnston

Jeff Johnston

unread,
Apr 27, 2009, 11:09:02 AM4/27/09
to JMesa

I wrote up an issue ticket for this.

http://code.google.com/p/jmesa/issues/detail?id=191

Jeff Johnston
Reply all
Reply to author
Forward
0 new messages