X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;ds=sidebyside;f=manifold%2Fjs%2Fplugin.js;h=dd12379dcc1c2384c08e3dc3543b5980741c8829;hb=05289ac1e6d9493b585bf0d6bb249d241eee99e2;hp=b72cc30cd81116a0b9d34dfdf07746b2ae89148f;hpb=8c344999d6ee3b3a9172a1068a77c83af77a7aee;p=myslice.git diff --git a/manifold/js/plugin.js b/manifold/js/plugin.js index b72cc30c..dd12379d 100644 --- a/manifold/js/plugin.js +++ b/manifold/js/plugin.js @@ -94,6 +94,9 @@ var Plugin = Class.extend({ case DONE: fn = 'query_done'; break; + case FIELD_STATE_CHANGED: + fn = 'field_state_changed'; + break; default: return; } // switch @@ -197,6 +200,50 @@ var Plugin = Class.extend({ return array[1]; }, + id_from_key: function(key_field, value) + { + + return key_field + manifold.separator + unfold.escape_id(value).replace(/\\/g, ''); + }, + + id_from_record: function(method, record) + { + var keys = manifold.metadata.get_key(method); + if (!keys) + return; + if (keys.length > 1) + return; + + var key = keys[0]; + switch (Object.toType(key)) { + case 'string': + if (!(key in record)) + return null; + return this.id_from_key(key, record[key]); + + default: + throw 'Not implemented'; + } + }, + + key_from_id: function(id) + { + // NOTE this works only for simple keys + + var array; + if (typeof id === 'string') { + array = id.split(manifold.separator); + } else { // We suppose we have an array ('object') + array = id; + } + + // arguments has the initial id but lacks the key field name (see id_from_key), so we are even + // we finally add +1 for the plugin_uuid at the beginning + return array[arguments.length + 1]; + }, + + /* SPIN */ + spin: function() { manifold.spin(this.element); @@ -207,4 +254,11 @@ var Plugin = Class.extend({ manifold.spin(this.element, false); }, + /* TEMPLATE */ + + load_template: function(name, ctx) + { + return Mustache.render(this.el(name).html(), ctx); + }, + });