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.source = '';
92                                     
93                                     if(!selected){
94                                        _this.viewPanel.setContent("Please select an saved version on the left"); 
95                                        return;
96                                     }
97                                     
98                                     _this.viewPanel.load( { url : baseURL + "/Roo/Events", method : 'GET' }, {_id : selected.data.id, _retrieve_source : 1}, function(oElement, bSuccess, oResponse){
99                                         
100                                         var res = Roo.decode(oResponse.responseText);
101                                         
102                                         if(!bSuccess || !res.success){
103                                             _this.viewPanel.setContent("Load data failed?!");
104                                         }
105                                         
106                                         if(typeof(res.data) === 'string'){
107                                             _this.viewPanel.setContent(res.data);
108                                             return;
109                                         }
110                                         
111                                         if(!_this.data.successFn){
112                                             Roo.MessageBox.alert('Error', 'Please setup the successFn');
113                                             return;
114                                         }
115                                         
116                                         _this.source = _this.data.successFn(res);
117                                 
118                                         _this.viewPanel.setContent(_this.source);
119                                         
120                                     });
121                                 }
122                             },
123                             singleSelect : true
124                         },
125                         dataSource : {
126                             xtype: 'Store',
127                             xns: Roo.data,
128                             listeners : {
129                                 beforeload : function (_self, o)
130                                 {
131                                     o.params = o.params || {};
132                                     
133                                     if(typeof(_this.data) == 'undefined'){
134                                         this.removeAll();
135                                         return false;
136                                     }
137                                 
138                                     var d = Roo.apply({}, _this.data);
139                                     delete d.successFn;
140                                 
141                                     Roo.apply(o.params, d);
142                                     
143                                 },
144                                 load : function (_self, records, options)
145                                 {
146                                     var sm = _this.grid.getSelectionModel();
147                                     if (!sm.getSelections().length) {
148                                         sm.selectFirstRow();
149                                         
150                                         sm.fireEvent('afterselectionchange', sm);
151                                     }
152                                 }
153                             },
154                             remoteSort : true,
155                             sortInfo : { field : 'event_when', direction: 'DESC' },
156                             proxy : {
157                                 xtype: 'HttpProxy',
158                                 xns: Roo.data,
159                                 method : 'GET',
160                                 url : baseURL + '/Roo/Events.php'
161                             },
162                             reader : {
163                                 xtype: 'JsonReader',
164                                 xns: Roo.data,
165                                 id : 'id',
166                                 root : 'data',
167                                 totalProperty : 'total',
168                                 fields : [
169                                     {
170                                         'name': 'id',
171                                         'type': 'int'
172                                     },
173                                     {
174                                         'name': 'event_when',
175                                         'type': 'string'
176                                     }
177                                 ]
178                             }
179                         },
180                         footer : {
181                             xtype: 'PagingToolbar',
182                             xns: Roo,
183                             displayInfo : false,
184                             pageSize : 25
185                         },
186                         colModel : [
187                             {
188                                 xtype: 'ColumnModel',
189                                 xns: Roo.grid,
190                                 dataIndex : 'event_when',
191                                 header : 'Date',
192                                 width : 100,
193                                 renderer : function(v) { return String.format('{0}', v ? v.format('Y-m-d H:i:s') : ''); }
194                             }
195                         ]
196                     }
197                 },
198                 {
199                     xtype: 'ContentPanel',
200                     xns: Roo,
201                     listeners : {
202                         render : function (_self)
203                         {
204                             _this.viewPanel = _self;
205                         }
206                     },
207                     autoScroll : true,
208                     background : false,
209                     fitContainer : true,
210                     fitToFrame : true,
211                     region : 'center'
212                 }
213             ],
214             center : {
215                 xtype: 'LayoutRegion',
216                 xns: Roo
217             },
218             west : {
219                 xtype: 'LayoutRegion',
220                 xns: Roo,
221                 split : true,
222                 width : 200
223             },
224             buttons : [
225                 {
226                     xtype: 'Button',
227                     xns: Roo,
228                     listeners : {
229                         click : function() {
230                             _this.dialog.hide();
231                         }
232                     },
233                     text : "Cancel"
234                 },
235                 {
236                     xtype: 'Button',
237                     xns: Roo,
238                     listeners : {
239                         click : function() {
240                         
241                             _this.dialog.hide();
242                             
243                             if (_this.callback && _this.source != '') {
244                                 _this.callback.call(this, _this.source);
245                             }
246                         }
247                     },
248                     text : "OK"
249                 }
250             ]
251         });
252     }
253 };