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             background : false,
48             closable : false,
49             collapsible : false,
50             height : 500,
51             modal : true,
52             resizable : false,
53             title : "Saved Version",
54             width : 800,
55             items : [
56                 {
57                     xtype: 'GridPanel',
58                     xns: Roo,
59                     listeners : {
60                         activate : function() {
61                             _this.panel = this;
62                             if (_this.grid) {
63                                 _this.grid.footer.onClick('first');
64                             }
65                         }
66                     },
67                     background : false,
68                     fitContainer : true,
69                     fitToframe : true,
70                     region : 'west',
71                     tableName : 'Images',
72                     title : "Images",
73                     grid : {
74                         xtype: 'Grid',
75                         xns: Roo.grid,
76                         listeners : {
77                             render : function() 
78                             {
79                                 _this.grid = this; 
80                                 
81                                 if (_this.panel.active) {
82                                    this.footer.onClick('first');
83                                 }
84                             }
85                         },
86                         autoExpandColumn : 'event_when',
87                         loadMask : true,
88                         sm : {
89                             xtype: 'RowSelectionModel',
90                             xns: Roo.grid,
91                             listeners : {
92                                 afterselectionchange : function (_self)
93                                 {
94                                     var selected = this.getSelected();
95                                     
96                                     _this.viewPanel.load( { url : baseURL + "/Roo/Events", method : 'GET' }, {_id : selected.data.id, _retrieve_source : 1}, function(oElement, bSuccess, oResponse){
97                                         
98                                         _this.source = '';
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                             },
145                             remoteSort : true,
146                             sortInfo : { field : 'event_when', direction: 'DESC' },
147                             proxy : {
148                                 xtype: 'HttpProxy',
149                                 xns: Roo.data,
150                                 method : 'GET',
151                                 url : baseURL + '/Roo/Events.php'
152                             },
153                             reader : {
154                                 xtype: 'JsonReader',
155                                 xns: Roo.data,
156                                 id : 'id',
157                                 root : 'data',
158                                 totalProperty : 'total',
159                                 fields : [
160                                     {
161                                         'name': 'id',
162                                         'type': 'int'
163                                     },
164                                     {
165                                         'name': 'event_when',
166                                         'type': 'string'
167                                     }
168                                 ]
169                             }
170                         },
171                         footer : {
172                             xtype: 'PagingToolbar',
173                             xns: Roo,
174                             displayInfo : false,
175                             pageSize : 25
176                         },
177                         colModel : [
178                             {
179                                 xtype: 'ColumnModel',
180                                 xns: Roo.grid,
181                                 dataIndex : 'event_when',
182                                 header : 'Date',
183                                 width : 100,
184                                 renderer : function(v) { return String.format('{0}', v ? v.format('Y-m-d H:i:s') : ''); }
185                             }
186                         ]
187                     }
188                 },
189                 {
190                     xtype: 'ContentPanel',
191                     xns: Roo,
192                     listeners : {
193                         render : function (_self)
194                         {
195                             _this.viewPanel = _self;
196                         }
197                     },
198                     autoScroll : true,
199                     background : false,
200                     fitContainer : true,
201                     fitToFrame : true,
202                     region : 'center'
203                 }
204             ],
205             center : {
206                 xtype: 'LayoutRegion',
207                 xns: Roo
208             },
209             west : {
210                 xtype: 'LayoutRegion',
211                 xns: Roo,
212                 split : true,
213                 width : 200
214             },
215             buttons : [
216                 {
217                     xtype: 'Button',
218                     xns: Roo,
219                     listeners : {
220                         click : function() {
221                             _this.dialog.hide();
222                         }
223                     },
224                     text : "Cancel"
225                 },
226                 {
227                     xtype: 'Button',
228                     xns: Roo,
229                     listeners : {
230                         click : function() {
231                         
232                             _this.dialog.hide();
233                             
234                             if (_this.callback && _this.source != '') {
235                                 _this.callback.call(this, _this.source);
236                             }
237                         }
238                     },
239                     text : "OK"
240                 }
241             ]
242         });
243     }
244 };