From: Stephen Burrows Date: Fri, 1 Apr 2011 21:24:07 +0000 (-0400) Subject: Added __unicode__ to loaded fk data. Added doubleclick loading of model instances... X-Git-Url: http://git.ithinksw.org/philo.git/commitdiff_plain/46d04058ae4f5a7fa50d76c28f328c972466743f Added __unicode__ to loaded fk data. Added doubleclick loading of model instances from model grids. Added caching of model instance forms - only one edit form can be open at once. --- diff --git a/contrib/gilbert/media/gilbert/lib/models.js b/contrib/gilbert/media/gilbert/lib/models.js index 8d33dca..427f92d 100644 --- a/contrib/gilbert/media/gilbert/lib/models.js +++ b/contrib/gilbert/media/gilbert/lib/models.js @@ -44,9 +44,10 @@ Gilbert.lib.models.Model = Ext.extend(Object, { Gilbert.lib.models.ModelInstance = Ext.extend(Object, { - constructor: function (model, pk) { + constructor: function (model, pk, __unicode__) { this.model = model; this.pk = pk; + this.__unicode__ = __unicode__ }, }); @@ -56,7 +57,7 @@ Ext.data.Types.GILBERTMODELFOREIGNKEY = { convert: function (v, data) { if (v) { - return new Gilbert.lib.models.ModelInstance(Gilbert.get_model(v.app_label, v.name), v.pk); + return new Gilbert.lib.models.ModelInstance(Gilbert.get_model(v.app_label, v.name), v.pk, v.__unicode__); } else { return null; } diff --git a/contrib/gilbert/media/gilbert/plugins/models.js b/contrib/gilbert/media/gilbert/plugins/models.js index 61fa7fb..ab36f36 100644 --- a/contrib/gilbert/media/gilbert/plugins/models.js +++ b/contrib/gilbert/media/gilbert/plugins/models.js @@ -262,6 +262,16 @@ Gilbert.lib.plugins.models.ui.ModelPanel = Ext.extend(Ext.Panel, { contextmenu.showAt(e.xy); }); + grid.on('rowdblclick', function(grid, rowIndex, e) { + var record = grid.getStore().getAt(rowIndex) + plugin.create_instance_window(model, record.id, function (win) { + win.on('saved', function () { + store.reload(); + }); + win.show(); + }); + }); + grid.getSelectionModel().on('selectionchange', function (selmodel) { if (selmodel.hasSelection()) { edit_action.setDisabled(false); @@ -328,6 +338,8 @@ Gilbert.lib.plugins.models.Plugin = Ext.extend(Gilbert.lib.plugins.Plugin, { application.on('model_registered', function (model) { this.handle_new_model(model); }, this); + + this.instance_windows = {} }, handle_new_model: function (model) { @@ -387,6 +399,11 @@ Gilbert.lib.plugins.models.Plugin = Ext.extend(Gilbert.lib.plugins.Plugin, { }, create_instance_window: function (model, pk, callback, config, cls) { + var win = this.instance_windows[[model.app_label, model.name, pk]]; + if (win != undefined){ + win.show() + return + } var pk = pk; var callback = callback; var application = this.application; @@ -394,7 +411,7 @@ Gilbert.lib.plugins.models.Plugin = Ext.extend(Gilbert.lib.plugins.Plugin, { var form_callback = function (form) { var oldform = form; - var win = application.create_window({ + var win = outer.instance_windows[[model.app_label, model.name, pk]] = application.create_window({ layout: 'fit', title: form.title, iconCls: form.iconCls, @@ -458,6 +475,9 @@ Gilbert.lib.plugins.models.Plugin = Ext.extend(Gilbert.lib.plugins.Plugin, { }, ], }); + win.on('close', function(){ + delete outer.instance_windows[[model.app_label, model.name, pk]]; + }); win.addEvents({ 'saved': true, }); @@ -479,5 +499,5 @@ Gilbert.lib.plugins.models.Plugin = Ext.extend(Gilbert.lib.plugins.Plugin, { Gilbert.on('ready', function (application) { - application.register_plugin('auth', new Gilbert.lib.plugins.models.Plugin()); + application.register_plugin('models', new Gilbert.lib.plugins.models.Plugin()); }); diff --git a/contrib/gilbert/plugins/models.py b/contrib/gilbert/plugins/models.py index ae97ee7..e3d559a 100644 --- a/contrib/gilbert/plugins/models.py +++ b/contrib/gilbert/plugins/models.py @@ -65,7 +65,7 @@ class ModelAdmin(Plugin): def data_serialize_model_instance(cls, obj): return { 'app_label': obj._meta.app_label, - 'name': obj._meta.object_name, + 'name': obj._meta.module_name, 'pk': obj.pk, '__unicode__': unicode(obj), }