This repository was archived by the owner on Sep 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmvc_crud_editor.js
More file actions
106 lines (88 loc) · 2.52 KB
/
mvc_crud_editor.js
File metadata and controls
106 lines (88 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*globals Ext, SWorks, console */
/*jslint glovar: true, undef: true, nomen: true */
Ext.namespace('SWorks');
SWorks.DialogEditor = Ext.extend(Ext.Window, {
width: 500,
height: 300,
autoCreate: true,
modal: true,
closable: false,
resizable: true,
draggable: true,
collapsible: false,
title: 'Edit',
layout: 'fit',
initComponent: function() {
Ext.apply(this, {
buttons: [{
text: "Save",
handler: this.onClickSave,
scope: this
}, {
text: "Close",
handler: this.onClickClose,
scope: this
}],
keys: [
{ key: 27, fn: this.onClickClose, scope: this },
{ key: Ext.EventObject.ENTER, fn: this.onClickSave, scope: this }
]
});
SWorks.DialogEditor.superclass.initComponent.call(this);
this.formPanel = this.findByType('form')[0];
this.formPanel.border = false;
this.formPanel.bodyStyle = "padding:10px";
this.form = this.formPanel.form;
this.on('hide', this.onHideDialog, this);
if (this.autoClose !== false) {
this.form.on('actioncomplete', this.closeOnSaveHandler, this);
}
},
loadRecord: function(record) {
if(!this.rendered) {
this.render(Ext.getBody());
}
// This can't be done in afterRender because the form won't have
// been rendered yet, just the window
this.controller.initFormIdempotent(this.form, this);
if(this.controller.dataModel.loadForm(this.form, record)) {
var saveBtn = this.buttons[0];
if( this.controller.isReadOnly(this.form) === true ) {
this.formPanel.el.addClass('read-only');
saveBtn.disable();
} else {
this.formPanel.el.removeClass('read-only');
saveBtn.enable();
}
this.show();
}
return this.form;
},
onHideDialog: function() {
this.keyMap.disable();
},
onClickSave: function(trigger, e) {
if(this.isFormButtonTrigger(trigger, e)) {
this.controller.saveForm(this.form, {
saveButton: true
});
}
},
closeOnSaveHandler: function(form, action) {
if (action.options.saveButton == true) {
this.hide();
}
},
onClickClose: function(trigger, e) {
if(this.isFormButtonTrigger(trigger, e)) {
this.hide();
}
},
isFormButtonTrigger: function(trigger, e) {
//Only function as a button handler on buttons, this makes
//sure ENTER still works on other buttons and textareas
//
var list = [ 'button', 'textarea' ];
return (typeof trigger == 'object' || list.indexOf(e.target.type) == -1);
}
});