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                     Roo.log('call show?');
40                     Roo.log(_this.grid.getSelectionModel().getSelected());
41                     if (!_this.grid.getSelectionModel().getSelected()) {
42                         _this.source = '';
43                         _this.viewPanel.setContent("Please select a version on the left");
44                     }
45                     
46                 }
47             },
48             background : false,
49             closable : false,
50             collapsible : false,
51             height : 500,
52             modal : true,
53             resizable : false,
54             title : "Saved Version",
55             width : 800,
56             items : [
57                 {
58                     xtype: 'GridPanel',
59                     xns: Roo,
60                     listeners : {
61                         activate : function() {
62                             _this.panel = this;
63                             if (_this.grid) {
64                                 _this.grid.footer.onClick('first');
65                             }
66                         }
67                     },
68                     background : false,
69                     fitContainer : true,
70                     fitToframe : true,
71                     region : 'west',
72                     tableName : 'Events',
73                     title : "Events",
74                     grid : {
75                         xtype: 'Grid',
76                         xns: Roo.grid,
77                         listeners : {
78                             render : function() 
79                             {
80                                 _this.grid = this; 
81                                 
82                                 if (_this.panel.active) {
83                                    this.footer.onClick('first');
84                                 }
85                             }
86                         },
87                         autoExpandColumn : 'event_when',
88                         loadMask : true,
89                         sm : {
90                             xtype: 'RowSelectionModel',
91                             xns: Roo.grid,
92                             listeners : {
93                                 afterselectionchange : function (_self)
94                                 {
95                                     var selected = this.getSelected();
96                                     
97                                     _this.viewPanel.load( { url : baseURL + "/Roo/Events", method : 'GET' }, {_id : selected.data.id, _retrieve_source : 1}, function(oElement, bSuccess, oResponse){
98                                         
99                                         _this.source = '';
100                                         
101                                         var res = Roo.decode(oResponse.responseText);
102                                         
103                                         if(!bSuccess || !res.success){
104                                             _this.viewPanel.setContent("Load data failed?!");
105                                         }
106                                         
107                                         if(typeof(res.data) === 'string'){
108                                             _this.viewPanel.setContent(res.data);
109                                             return;
110                                         }
111                                         
112                                         if(!_this.data.successFn){
113                                             Roo.MessageBox.alert('Error', 'Please setup the successFn');
114                                             return;
115                                         }
116                                         
117                                         _this.source = _this.data.successFn(res);
118                                 
119                                         _this.viewPanel.setContent(_this.source);
120                                         
121                                     });
122                                 }
123                             },
124                             singleSelect : true
125                         },
126                         dataSource : {
127                             xtype: 'Store',
128                             xns: Roo.data,
129                             listeners : {
130                                 beforeload : function (_self, o)
131                                 {
132                                     o.params = o.params || {};
133                                     
134                                     if(typeof(_this.data) == 'undefined'){
135                                         this.removeAll();
136                                         return false;
137                                     }
138                                 
139                                     var d = Roo.apply({}, _this.data);
140                                     delete d.successFn;
141                                 
142                                     Roo.apply(o.params, d);
143                                     
144                                 }
145                             },
146                             remoteSort : true,
147                             sortInfo : { field : 'event_when', direction: 'DESC' },
148                             proxy : {
149                                 xtype: 'HttpProxy',
150                                 xns: Roo.data,
151                                 method : 'GET',
152                                 url : baseURL + '/Roo/Events.php'
153                             },
154                             reader : {
155                                 xtype: 'JsonReader',
156                                 xns: Roo.data,
157                                 id : 'id',
158                                 root : 'data',
159                                 totalProperty : 'total',
160                                 fields : [
161                                     {
162                                         'name': 'id',
163                                         'type': 'int'
164                                     },
165                                     {
166                                         'name': 'event_when',
167                                         'type': 'string'
168                                     }
169                                 ]
170                             }
171                         },
172                         footer : {
173                             xtype: 'PagingToolbar',
174                             xns: Roo,
175                             displayInfo : false,
176                             pageSize : 25
177                         },
178                         colModel : [
179                             {
180                                 xtype: 'ColumnModel',
181                                 xns: Roo.grid,
182                                 dataIndex : 'event_when',
183                                 header : 'Date',
184                                 width : 100,
185                                 renderer : function(v) { return String.format('{0}', v ? v.format('Y-m-d H:i:s') : ''); }
186                             }
187                         ]
188                     }
189                 },
190                 {
191                     xtype: 'ContentPanel',
192                     xns: Roo,
193                     listeners : {
194                         render : function (_self)
195                         {
196                             _this.viewPanel = _self;
197                         }
198                     },
199                     autoScroll : true,
200                     background : false,
201                     fitContainer : true,
202                     fitToFrame : true,
203                     region : 'center'
204                 }
205             ],
206             center : {
207                 xtype: 'LayoutRegion',
208                 xns: Roo
209             },
210             west : {
211                 xtype: 'LayoutRegion',
212                 xns: Roo,
213                 split : true,
214                 width : 200
215             },
216             buttons : [
217                 {
218                     xtype: 'Button',
219                     xns: Roo,
220                     listeners : {
221                         click : function() {
222                             _this.dialog.hide();
223                         }
224                     },
225                     text : "Cancel"
226                 },
227                 {
228                     xtype: 'Button',
229                     xns: Roo,
230                     listeners : {
231                         click : function() {
232                         
233                             _this.dialog.hide();
234                             
235                             if (_this.callback && _this.source != '') {
236                                 _this.callback.call(this, _this.source);
237                             }
238                         }
239                     },
240                     text : "OK"
241                 }
242             ]
243         });
244     }
245 };