Pman.Dialog.CoreAutoSavePreview.bjs
[Pman.Core] / Pman.Dialog.CoreAutoSavePreview.js
1 //<script type="text/javascript">
2
3 // Auto generated file - created by app.Builder.js- do not edit directly (at present!)
4
5 Pman.Dialog.CoreAutoSavePreview = {
6
7     dialog : false,
8     callback:  false,
9
10     show : function(data, cb)
11     {
12         if (!this.dialog) {
13             this.create();
14         }
15
16         this.callback = cb;
17         this.data = data;
18         this.dialog.show(this.data._el);
19         if (this.form) {
20            this.form.reset();
21            this.form.setValues(data);
22            this.form.fireEvent('actioncomplete', this.form,  { type: 'setdata', data: data });
23         }
24
25     },
26
27     create : function()
28     {
29         var _this = this;
30         this.dialog = Roo.factory({
31             xtype: 'LayoutDialog',
32             xns: Roo,
33             listeners : {
34                 show : function (_self)
35                 {
36                     if(typeof(_this.data) != 'undefined'){
37                         _this.grid.footer.onClick('first');
38                     }
39                     
40                 }
41             },
42             background : false,
43             closable : false,
44             collapsible : false,
45             height : 500,
46             modal : true,
47             resizable : false,
48             title : "Saved Version",
49             width : 800,
50             items : [
51                 {
52                     xtype: 'GridPanel',
53                     xns: Roo,
54                     listeners : {
55                         activate : function() {
56                             _this.panel = this;
57                             if (_this.grid) {
58                                 _this.grid.footer.onClick('first');
59                             }
60                         }
61                     },
62                     background : false,
63                     fitContainer : true,
64                     fitToframe : true,
65                     region : 'west',
66                     tableName : 'Events',
67                     title : "Events",
68                     grid : {
69                         xtype: 'Grid',
70                         xns: Roo.grid,
71                         listeners : {
72                             render : function() 
73                             {
74                                 _this.grid = this; 
75                                 
76                                 if (_this.panel.active) {
77                                    this.footer.onClick('first');
78                                 }
79                             }
80                         },
81                         autoExpandColumn : 'event_when',
82                         loadMask : true,
83                         sm : {
84                             xtype: 'RowSelectionModel',
85                             xns: Roo.grid,
86                             listeners : {
87                                 afterselectionchange : function (_self)
88                                 {
89                                     var selected = this.getSelected();
90                                     
91                                     _this.viewPanel.load( { url : baseURL + "/Roo/Events", method : 'GET' }, {_id : selected.data.id, _retrieve_source : 1}, function(oElement, bSuccess, oResponse){
92                                         
93                                         _this.source = '';
94                                         
95                                         var res = Roo.decode(oResponse.responseText);
96                                         
97                                         if(!bSuccess || !res.success){
98                                             _this.viewPanel.setContent("Load data failed?!");
99                                         }
100                                         
101                                         if(typeof(res.data) === 'string'){
102                                             _this.viewPanel.setContent(res.data);
103                                             return;
104                                         }
105                                         
106                                         if(!_this.data.successFn){
107                                             Roo.MessageBox.alert('Error', 'Please setup the successFn');
108                                             return;
109                                         }
110                                         
111                                         _this.source = _this.data.successFn(res);
112                                 
113                                         _this.viewPanel.setContent(_this.source);
114                                         
115                                     });
116                                 }
117                             },
118                             singleSelect : true
119                         },
120                         dataSource : {
121                             xtype: 'Store',
122                             xns: Roo.data,
123                             listeners : {
124                                 beforeload : function (_self, o)
125                                 {
126                                     o.params = o.params || {};
127                                     
128                                     if(typeof(_this.data) == 'undefined'){
129                                         this.removeAll();
130                                         return false;
131                                     }
132                                 
133                                     var d = Roo.apply({}, _this.data);
134                                     delete d.successFn;
135                                 
136                                     Roo.apply(o.params, d);
137                                     
138                                 },
139                                 load : function (_self, records, options)
140                                 {
141                                     var sm = _this.grid.getSelectionModel();
142                                     if (!sm.getSelections().length) {
143                                         sm.selectFirstRow();
144                                         
145                                     }
146                                 }
147                             },
148                             remoteSort : true,
149                             sortInfo : { field : 'event_when', direction: 'DESC' },
150                             proxy : {
151                                 xtype: 'HttpProxy',
152                                 xns: Roo.data,
153                                 method : 'GET',
154                                 url : baseURL + '/Roo/Events.php'
155                             },
156                             reader : {
157                                 xtype: 'JsonReader',
158                                 xns: Roo.data,
159                                 id : 'id',
160                                 root : 'data',
161                                 totalProperty : 'total',
162                                 fields : [
163                                     {
164                                         'name': 'id',
165                                         'type': 'int'
166                                     },
167                                     {
168                                         'name': 'event_when',
169                                         'type': 'string'
170                                     }
171                                 ]
172                             }
173                         },
174                         footer : {
175                             xtype: 'PagingToolbar',
176                             xns: Roo,
177                             displayInfo : false,
178                             pageSize : 25
179                         },
180                         colModel : [
181                             {
182                                 xtype: 'ColumnModel',
183                                 xns: Roo.grid,
184                                 dataIndex : 'event_when',
185                                 header : 'Date',
186                                 width : 100,
187                                 renderer : function(v) { return String.format('{0}', v ? v.format('Y-m-d H:i:s') : ''); }
188                             }
189                         ]
190                     }
191                 },
192                 {
193                     xtype: 'ContentPanel',
194                     xns: Roo,
195                     listeners : {
196                         render : function (_self)
197                         {
198                             _this.viewPanel = _self;
199                         }
200                     },
201                     autoScroll : true,
202                     background : false,
203                     fitContainer : true,
204                     fitToFrame : true,
205                     region : 'center'
206                 }
207             ],
208             center : {
209                 xtype: 'LayoutRegion',
210                 xns: Roo
211             },
212             west : {
213                 xtype: 'LayoutRegion',
214                 xns: Roo,
215                 split : true,
216                 width : 200
217             },
218             buttons : [
219                 {
220                     xtype: 'Button',
221                     xns: Roo,
222                     listeners : {
223                         click : function() {
224                             _this.dialog.hide();
225                         }
226                     },
227                     text : "Cancel"
228                 },
229                 {
230                     xtype: 'Button',
231                     xns: Roo,
232                     listeners : {
233                         click : function() {
234                         
235                             _this.dialog.hide();
236                             
237                             if (_this.callback && _this.source != '') {
238                                 _this.callback.call(this, _this.source);
239                             }
240                         }
241                     },
242                     text : "OK"
243                 }
244             ]
245         });
246     }
247 };