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__
},
});
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;
}
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);
application.on('model_registered', function (model) {
this.handle_new_model(model);
}, this);
+
+ this.instance_windows = {}
},
handle_new_model: function (model) {
},
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;
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,
},
],
});
+ win.on('close', function(){
+ delete outer.instance_windows[[model.app_label, model.name, pk]];
+ });
win.addEvents({
'saved': true,
});
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());
});
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),
}