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