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