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                     if (!_this.grid.getSelectionModel().getSelected()) {
41                         _this.source = '';
42                         _this.viewPanel.setContent("Please select a version on the left");
43                     }
44                     
45                     
46                     
47                 }
48             },
49             background : false,
50             closable : false,
51             collapsible : false,
52             height : 500,
53             modal : true,
54             resizable : false,
55             title : "Saved Version",
56             width : 800,
57             items : [
58                 {
59                     xtype: 'GridPanel',
60                     xns: Roo,
61                     listeners : {
62                         activate : function() {
63                             _this.panel = this;
64                             if (_this.grid) {
65                                 _this.grid.footer.onClick('first');
66                             }
67                         }
68                     },
69                     background : false,
70                     fitContainer : true,
71                     fitToframe : true,
72                     region : 'west',
73                     tableName : 'Images',
74                     title : "Images",
75                     grid : {
76                         xtype: 'Grid',
77                         xns: Roo.grid,
78                         listeners : {
79                             render : function() 
80                             {
81                                 _this.grid = this; 
82                                 
83                                 if (_this.panel.active) {
84                                    this.footer.onClick('first');
85                                 }
86                             }
87                         },
88                         autoExpandColumn : 'event_when',
89                         loadMask : true,
90                         sm : {
91                             xtype: 'RowSelectionModel',
92                             xns: Roo.grid,
93                             listeners : {
94                                 afterselectionchange : function (_self)
95                                 {
96                                     var selected = this.getSelected();
97                                     
98                                     _this.viewPanel.load( { url : baseURL + "/Roo/Events", method : 'GET' }, {_id : selected.data.id, _retrieve_source : 1}, function(oElement, bSuccess, oResponse){
99                                         
100                                         _this.source = '';
101                                         
102                                         var res = Roo.decode(oResponse.responseText);
103                                         
104                                         if(!bSuccess || !res.success){
105                                             _this.viewPanel.setContent("Load data failed?!");
106                                         }
107                                         
108                                         if(typeof(res.data) === 'string'){
109                                             _this.viewPanel.setContent(res.data);
110                                             return;
111                                         }
112                                         
113                                         if(!_this.data.successFn){
114                                             Roo.MessageBox.alert('Error', 'Please setup the successFn');
115                                             return;
116                                         }
117                                         
118                                         _this.source = _this.data.successFn(res);
119                                 
120                                         _this.viewPanel.setContent(_this.source);
121                                         
122                                     });
123                                 }
124                             },
125                             singleSelect : true
126                         },
127                         dataSource : {
128                             xtype: 'Store',
129                             xns: Roo.data,
130                             listeners : {
131                                 beforeload : function (_self, o)
132                                 {
133                                     o.params = o.params || {};
134                                     
135                                     if(typeof(_this.data) == 'undefined'){
136                                         this.removeAll();
137                                         return false;
138                                     }
139                                 
140                                     var d = Roo.apply({}, _this.data);
141                                     delete d.successFn;
142                                 
143                                     Roo.apply(o.params, d);
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 };