e554487e7cad1bc2154625e91c3cc71893f8137a
[roojs1] / examples / dialog / test-2.js
1 var uploadCropbox = {
2     dialog : false,
3     callback : false,
4
5     show : function(data, cb)
6     {
7         if (!this.dialog) {
8             this.create();
9         }
10
11         this.callback = cb;
12         this.data = data;
13         this.dialog.show();
14     },
15
16     create : function()
17     {
18         var _this = this;
19         this.dialog = Roo.factory({
20             xns : Roo,
21             xtype : 'LayoutDialog',
22             width : 800,
23             height : 600,
24             center : {
25                 xns : Roo,
26                 xtype : 'LayoutRegion'
27             },
28             items : [
29                 {
30                     xtype: 'ContentPanel',
31                     xns: Roo,
32                     region : "center",
33                     items : [
34                         {
35                             xtype : 'UploadCropbox',
36                             xns : Roo.dialog,
37                             minWidth : 720,
38                             minHeight : 480,
39                             outputMaxWidth : 1300,
40                             url: 'http://localhost/web.MediaOutreach/press.local.php/Roo/Images.php',
41                             buttons: [],
42                             listeners : {
43                                 render : function (_self)
44                                 {
45                                     _this.cropbox = _self;
46                                 },
47                                 loadcanvas : function (_self, imageEl)
48                                 {
49                                     if(imageEl.OriginWidth < 720) {
50                                         Roo.Msg.show({
51                                             title: 'Error',
52                                             msg: "Image width should be at least 720",
53                                             buttons: {ok : true},
54                                             fn: function(res) {
55                                                 _this.cropbox.selectorEl.dom.value = '';
56                                                 _this.cropbox.selectorEl.dom.click();
57                                             }
58                                         });
59                                         return false;
60                                     }
61                                 },
62                                 arrange : function (_self, formData)
63                                 {
64                                     formData.append("onid", "43024");
65                                     formData.append("ontable", "pressrelease_boilerplate");
66                                 }
67                             }
68                         }
69                     ]
70                 }
71             ],
72             buttons : [
73                 {
74                     xtype : 'Button',
75                     xns : Roo,
76                     text : 'Save',
77                     listeners : {
78                         click : function () {
79                             _this.cropbox.crop();
80                         }   
81                     }
82                 },
83                 {
84                     xtype : 'Button',
85                     xns : Roo,
86                     text : 'Cancel',
87                     listeners : {
88                         click : function () {
89                             _this.dialog.hide();
90                         }   
91                     }
92                 }
93             ]
94         });
95     }
96 }
97
98 var test = {
99
100     dialog : false,
101     callback : false,
102
103     show : function(data, cb)
104     {
105         if (!this.dialog) {
106             this.create();
107         }
108
109         this.callback = cb;
110         this.data = data;
111         this.dialog.show();
112     },
113
114     create : function()
115     {
116         var _this = this;
117         this.dialog = Roo.factory({
118             xns : Roo,
119             xtype : 'LayoutDialog',
120             width : 600,
121             height : 450,
122             center : {
123                 xns : Roo,
124                 xtype : 'LayoutRegion'
125             },
126             items : [
127                 {
128                     xns : Roo,
129                     xtype: 'GridPanel',
130                     region : "center",
131                     grid : {
132                         xns : Roo.grid,
133                         xtype : 'Grid',
134                         cm : [
135                             {
136                                 xns : Roo.grid,
137                                 xtype : 'ColumnModel',
138                                 header : 'test'
139                             }
140                         ],
141                         ds : {
142                             xns: Roo.data,
143                             xtype: 'Store'
144                         },
145                         toolbar : {
146                             xns: Roo,
147                             xtype: 'Toolbar',
148                             items : [
149                                 { 
150                                     xtype : 'Button',
151                                     text : 'Add',
152                                     listeners : {
153                                         click : function () {
154                                             uploadCropbox.show();
155                                             document.body.onfocus = function(e) {
156                                                 if(!uploadCropbox.cropbox.selectorEl.dom.files.length) {
157                                                     uploadCropbox.dialog.hide();
158                                                 }
159                                             }
160                                             uploadCropbox.cropbox.selectorEl.dom.click();
161                                         }
162                                     }
163                                 }
164                             ]
165                         }
166                     }
167                 }
168             ],
169         });
170     }
171 }
172
173 Roo.onReady(function() {
174     
175     Roo.get('show-dialog-btn').on('click',function () {
176         test.show({});
177     });
178 });