Added __unicode__ to loaded fk data. Added doubleclick loading of model instances...
authorStephen Burrows <stephen.r.burrows@gmail.com>
Fri, 1 Apr 2011 21:24:07 +0000 (17:24 -0400)
committerStephen Burrows <stephen.r.burrows@gmail.com>
Wed, 6 Apr 2011 20:58:31 +0000 (16:58 -0400)
contrib/gilbert/media/gilbert/lib/models.js
contrib/gilbert/media/gilbert/plugins/models.js
contrib/gilbert/plugins/models.py

index 8d33dca..427f92d 100644 (file)
@@ -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;
                }
index 61fa7fb..ab36f36 100644 (file)
@@ -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());
 });
index ae97ee7..e3d559a 100644 (file)
@@ -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),
                }