DataObjects/Cms_page.php
[Pman.Cms] / Pman.Dialog.CmsProduct.js
index 8d77606..0693f2c 100644 (file)
@@ -33,6 +33,7 @@ Pman.Dialog.CmsProduct = {
             closable : false,
             collapsible : false,
             height : 380,
+            modal : true,
             resizable : false,
             title : "Edit / Create Product",
             width : 700,
@@ -49,8 +50,9 @@ Pman.Dialog.CmsProduct = {
                                 actioncomplete : function(_self,action)
                                 {
                                     if (action.type == 'setdata') {
-                                       //_this.dialog.el.mask("Loading");
+                                 
                                        if (_this.data.id) {
+                                           _this.dialog.el.mask("Loading");
                                            this.load({ method: 'GET', params: { '_id' : _this.data.id }});
                                             return;
                                        }
@@ -65,11 +67,16 @@ Pman.Dialog.CmsProduct = {
                                     if (action.type =='submit') {
                                     
                                         _this.dialog.el.unmask();
-                                        _this.dialog.hide();
-                                    
+                                      
+                                        _this.data.id = action.result.data.id;
+                                        _this.form.findField('id').setValue(_this.data.id);
                                          if (_this.callback) {
-                                            _this.callback.call(_this, _this.form.getValues());
+                                            var res = _this.callback.call(_this, _this.form.getValues());
+                                            if (res === false) {
+                                                return;
+                                            }
                                          }
+                                         _this.dialog.hide();
                                          _this.form.reset();
                                          return;
                                     }
@@ -126,6 +133,11 @@ Pman.Dialog.CmsProduct = {
                                         }
                                     ]
                                 },
+                                {
+                                    xtype: 'Hidden',
+                                    xns: Roo.form,
+                                    name : 'category_id'
+                                },
                                 {
                                     xtype: 'Hidden',
                                     xns: Roo.form,
@@ -142,16 +154,17 @@ Pman.Dialog.CmsProduct = {
                         activate : function (_self)
                         {
                            //console.log('activate');
-                           if (!_this.loaded) {
-                             return;
+                           if ( _this.imageView ){ 
+                              _this.imageView.loadImages();
                            }
-                           _this.imageView.loadImages();
+                        
                            if (_this.hasUploadWatch) {
                              return;
                            }
                            _this.hasUploadWatch =true;
-                              _this.uploadSending =false;
-                               window.setInterval( function() {
+                           _this.uploadSending =false;
+                           window.setInterval( function()
+                            {
                                 var val = _this.uploadForm.findField('imageUpload').getValue();
                                 if (!val || !val.length) {
                                     return;
@@ -160,6 +173,20 @@ Pman.Dialog.CmsProduct = {
                                 if (_this.uploadSending) {
                                     return;
                                 }
+                                
+                                if (!_this.data.id) {
+                                    // trigger a save..
+                                    var cb = _this.callback;
+                                    _this.callback = function() {
+                                        _this.uploadSending = false;
+                                        _this.callback = cb;
+                                        return false;
+                                    }
+                                    _this.uploadSending = true;
+                                     _this.form.doAction("submit");
+                                    return;
+                                }
+                                
                                  _this.uploadSending =true;
                                 _this.uploadForm.findField('onid').setValue(_this.data.id);
                                 _this.uploadForm.el.mask("Sending");
@@ -222,6 +249,13 @@ Pman.Dialog.CmsProduct = {
                                         jsonRoot : 'data',
                                         singleSelect : true,
                                         loadImages : function() {
+                                            if (!_this.data.id) {
+                                                 this.clearSelections();
+                                                this.el.update("");
+                                                this.jsonData = [];
+                                                return; 
+                                            } 
+                                        
                                            this.load({
                                                 url : baseURL + '/Roo/Images.php',
                                                 method : 'GET',
@@ -238,7 +272,7 @@ Pman.Dialog.CmsProduct = {
                                             xtype: 'Template',
                                             xns: Roo,
                                             html : '<div class="thumb-wrap"> ' + 
-                                              '<div class="thumb"><img  src="{url}" class="thumb-img"></div>' + 
+                                              '<div class="thumb"><img  src="'+ baseURL + '/Images/Thumb/150/{id}/{filename}" class="thumb-img"></div>' + 
                                             '</div>'
                                         }
                                     }
@@ -258,12 +292,15 @@ Pman.Dialog.CmsProduct = {
                                                      Roo.MessageBox.alert("Error", "Select an Image");
                                                      return;
                                                    }
-                                                   var id  = _this.imageView.getNodeData(_this.imageView.getSelectedNodes()[0]).id;
+                                                   var n = _this.imageView.getNodeData(_this.imageView.getSelectedNodes()[0]);
+                                                
                                                    // open a new window with this file in..
-                                                   
+                                                   Pman.download( {
+                                                       url: baseURL + '/Images/Download/' + n.id  + '/' + n.filename
+                                                   });
                                                 }
                                             },
-                                            text : "View / Download"
+                                            text : "Download"
                                         },
                                         {
                                             xtype: 'Fill',
@@ -290,16 +327,7 @@ Pman.Dialog.CmsProduct = {
                                                       method : 'GET',
                                                       success : function() {
                                                           _this.imageView.el.unmask();
-                                                           _this.imageView.load({
-                                                                url : baseURL + '/Roo/Images.php',
-                                                                method : 'GET',
-                                                                params : {
-                                                                   on_table : 'SellerProduct',
-                                                                   on_id : _this.data.id,
-                                                                   'query[imagesize]' : 150
-                                                                },
-                                                                text : 'Loading'
-                                                           });
+                                                           _this.imageView.loadImages();
                                                       },
                                                       failure : function() {
                                                            _this.imageView.el.unmask();
@@ -309,7 +337,7 @@ Pman.Dialog.CmsProduct = {
                                                   });
                                                  }
                                             },
-                                            text : "Delete Selected File or  Image"
+                                            text : "Delete File/Image"
                                         }
                                     ]
                                 }
@@ -340,16 +368,7 @@ Pman.Dialog.CmsProduct = {
                                                      _this.uploadForm.reset();
                                                        _this.uploadSending = false;
                                                       _this.uploadForm.el.unmask();         
-                                                     _this.imageView.load({
-                                                            url : baseURL + '/Roo/Images.php',
-                                                            method : 'GET',
-                                                            params : {
-                                                               on_table : 'SellerProduct',
-                                                               on_id : _this.data.id,
-                                                               'query[imagesize]' : 150
-                                                            },
-                                                            text : 'Loading'
-                                                       });
+                                                     _this.imageView.loadImages();
                                                      return;
                                                 }