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