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                                         sm.fireEvent('afterselectionchange', sm);
146                                     }
147                                 }
148                             },
149                             remoteSort : true,
150                             sortInfo : { field : 'event_when', direction: 'DESC' },
151                             proxy : {
152                                 xtype: 'HttpProxy',
153                                 xns: Roo.data,
154                                 method : 'GET',
155                                 url : baseURL + '/Roo/Events.php'
156                             },
157                             reader : {
158                                 xtype: 'JsonReader',
159                                 xns: Roo.data,
160                                 id : 'id',
161                                 root : 'data',
162                                 totalProperty : 'total',
163                                 fields : [
164                                     {
165                                         'name': 'id',
166                                         'type': 'int'
167                                     },
168                                     {
169                                         'name': 'event_when',
170                                         'type': 'string'
171                                     }
172                                 ]
173                             }
174                         },
175                         footer : {
176                             xtype: 'PagingToolbar',
177                             xns: Roo,
178                             displayInfo : false,
179                             pageSize : 25
180                         },
181                         colModel : [
182                             {
183                                 xtype: 'ColumnModel',
184                                 xns: Roo.grid,
185                                 dataIndex : 'event_when',
186                                 header : 'Date',
187                                 width : 100,
188                                 renderer : function(v) { return String.format('{0}', v ? v.format('Y-m-d H:i:s') : ''); }
189                             }
190                         ]
191                     }
192                 },
193                 {
194                     xtype: 'ContentPanel',
195                     xns: Roo,
196                     listeners : {
197                         render : function (_self)
198                         {
199                             _this.viewPanel = _self;
200                         }
201                     },
202                     autoScroll : true,
203                     background : false,
204                     fitContainer : true,
205                     fitToFrame : true,
206                     region : 'center'
207                 }
208             ],
209             center : {
210                 xtype: 'LayoutRegion',
211                 xns: Roo
212             },
213             west : {
214                 xtype: 'LayoutRegion',
215                 xns: Roo,
216                 split : true,
217                 width : 200
218             },
219             buttons : [
220                 {
221                     xtype: 'Button',
222                     xns: Roo,
223                     listeners : {
224                         click : function() {
225                             _this.dialog.hide();
226                         }
227                     },
228                     text : "Cancel"
229                 },
230                 {
231                     xtype: 'Button',
232                     xns: Roo,
233                     listeners : {
234                         click : function() {
235                         
236                             _this.dialog.hide();
237                             
238                             if (_this.callback && _this.source != '') {
239                                 _this.callback.call(this, _this.source);
240                             }
241                         }
242                     },
243                     text : "OK"
244                 }
245             ]
246         });
247     }
248 };