DataObjects/pman.links.ini
[Pman.Core] / Pman.Dialog.CoreMailingListMessage.js
index 8ecece6..c39c5bc 100644 (file)
@@ -92,7 +92,7 @@ Pman.Dialog.CoreMailingListMessage = {
                                                 click : function (_self, e)
                                                 {
                                                     Pman.Dialog.CoreImportUrl.show({
-                                                        target : '/Crm/ImportHtml.php'
+                                                        target : '/Core/ImportMailMessage.php'
                                                     }, function(data) {
                                                         if  (data) {
                                                           //  Roo.log(data);
@@ -110,7 +110,7 @@ Pman.Dialog.CoreMailingListMessage = {
                                                 click : function (_self, e)
                                                 {
                                                     Pman.Dialog.Image.show({
-                                                        _url : baseURL + '/Crm/ImportHtml.php'
+                                                        _url : baseURL + '/Core/ImportMailMessage.php'
                                                     }, function(data) {
                                                         if  (data) {
                                                             _this.form.findField('bodytext').setValue(data);
@@ -141,7 +141,7 @@ Pman.Dialog.CoreMailingListMessage = {
                                                     var l = document.location;
                                                     new Pman.Request({
                                                 
-                                                        url : baseURL + '/Crm/ImportHtml.php',
+                                                        url : baseURL + '/Core/ImportMailMessage.php',
                                                 
                                                         method: 'POST',
                                                         mask : "Loading",
@@ -164,8 +164,25 @@ Pman.Dialog.CoreMailingListMessage = {
                             {
                                 xtype: 'ComboBox',
                                 xns: Roo.form,
+                                listeners : {
+                                    select : function (combo, record, index)
+                                    {
+                                       
+                                    /*
+                                        (function() { 
+                                            combo.setValue('');
+                                        }).defer(100);
+                                    */    
+                                        if(!record){
+                                            return;
+                                        }
+                                        _this.form.findField('bodytext').setValue(record.data.content);
+                                    
+                                    }
+                                },
                                 allowBlank : true,
-                                displayField : 'name',
+                                alwaysQuery : true,
+                                displayField : 'file',
                                 editable : false,
                                 emptyText : "Select Template",
                                 fieldLabel : 'Template',
@@ -178,10 +195,10 @@ Pman.Dialog.CoreMailingListMessage = {
                                 pageSize : 20,
                                 qtip : "Select Template",
                                 selectOnFocus : true,
-                                tpl : '<div class="x-grid-cell-text x-btn button"><b>{name}</b> </div>',
+                                tpl : '<div class="x-grid-cell-text x-btn button"><b>{file}</b> </div>',
                                 triggerAction : 'all',
                                 typeAhead : true,
-                                valueField : 'name',
+                                valueField : 'file',
                                 width : 200,
                                 store : {
                                     xtype: 'Store',
@@ -194,7 +211,7 @@ Pman.Dialog.CoreMailingListMessage = {
                                         }
                                     },
                                     remoteSort : true,
-                                    sortInfo : { direction : 'DESC', field: 'name' },
+                                    sortInfo : { direction : 'DESC', field: 'file' },
                                     proxy : {
                                         xtype: 'HttpProxy',
                                         xns: Roo.data,
@@ -204,10 +221,10 @@ Pman.Dialog.CoreMailingListMessage = {
                                     reader : {
                                         xtype: 'JsonReader',
                                         xns: Roo.data,
-                                        id : 'bankaccnt_id',
+                                        id : 'name',
                                         root : 'data',
                                         totalProperty : 'total',
-                                        fields : [{"name":"name","type":"string"},{"name":"body","type":"string"}]
+                                        fields : [{"name":"file","type":"string"},{"name":"content","type":"string"}]
                                     }
                                 }
                             },
@@ -287,16 +304,23 @@ Pman.Dialog.CoreMailingListMessage = {
                                             {
                                                
                                                 if (action.type == 'setdata') {
-                                                   // _this.loaded_data = _this.form.getValues();
-                                            
+                                                
+                                                    _this.data.module = _this.data.module || 'crm';
+                                                    
+                                                    _this.form.url = baseURL + '/Roo/' + _this.data.module + '_mailing_list_message.php';
+                                                    
+                                                    _this.html_preview.hide();
+                                                    _this.preview_btn.hide();
+                                                        
                                                     if(_this.data.id*1 > 0){
                                                         _this.dialog.el.mask("Loading");
                                                         this.load({ method: 'GET', params: { '_id' : _this.data.id }});
-                                                        _this.html_preview.show();
+                                                        if(_this.data.module == 'crm'){
+                                                            _this.html_preview.show();
+                                                        }
                                                         _this.preview_btn.show();
+                                                        
                                                     } else {
-                                                        _this.html_preview.hide();
-                                                        _this.preview_btn.hide();
                                                         _this.form.setValues({
                                                             'from_name' : Pman.Login.authUser.name,
                                                             'from_email' : Pman.Login.authUser.email
@@ -336,6 +360,8 @@ Pman.Dialog.CoreMailingListMessage = {
                                             
                                             var s = Roo.get(_this.form.findField('bodytext').doc.documentElement);
                                             
+                                            var ontable = (_this.data.module) ? _this.data.module + '_mailing_list_message' : 'crm_mailing_list_message';
+                                            
                                             var nodes = [];
                                             s.select('img[src]').each(function(i) {
                                                 nodes.push(i.dom);
@@ -362,7 +388,7 @@ Pman.Dialog.CoreMailingListMessage = {
                                                     method : 'POST',
                                                     params : {
                                                         onid : _this.form.findField('id').getValue(),
-                                                        ontable : 'core_mailing_list_message' ,
+                                                        ontable : ontable ,
                                                         _remote_upload : i.src
                                                     },
                                                     success : function(res){
@@ -515,7 +541,7 @@ Pman.Dialog.CoreMailingListMessage = {
                                                                                     {
                                                                                         var id = _this.form.findField('id').getValue() * 1;    
                                                                                         if (!id) {
-                                                                                            Roo.MessageBox.alert("Error", "Save email template first");
+                                                                                            Roo.MessageBox.alert("Error", "Save message first");
                                                                                             return false;
                                                                                         }
                                                                                     }
@@ -546,11 +572,11 @@ Pman.Dialog.CoreMailingListMessage = {
                                                                                         
                                                                                             var id = _this.form.findField('id').getValue() * 1;    
                                                                                             if (!id) {
-                                                                                                Roo.MessageBox.alert("Error", "Save press release first");
+                                                                                                Roo.MessageBox.alert("Error", "Save email template first");
                                                                                                 return false;
                                                                                             }
                                                                                             o.params.onid = id
-                                                                                            o.params.ontable = 'crm_mailing_list_message';
+                                                                                            o.params.ontable = 'core_mailing_list_message';
                                                                                             
                                                                                            // o.params.imgtype = 'PressRelease';
                                                                                             //o.params['query[imagesize]'] = '150x150';
@@ -660,7 +686,7 @@ Pman.Dialog.CoreMailingListMessage = {
                                                                 var p = _this.form.findField('plaintext');
                                                                 
                                                                 new Pman.Request({\r
-                                                                    url : baseURL + '/Crm/ImportHtml.php',\r
+                                                                    url : baseURL + '/Core/ImportMailMessage.php',\r
                                                                     method : 'POST',\r
                                                                     params : {
                                                                       bodytext : h,\r
@@ -765,7 +791,8 @@ Pman.Dialog.CoreMailingListMessage = {
                                     if(_this.data.id * 1 >= 0)
                                     {
                                         options.params.onid = _this.data.id;
-                                        options.params.ontable = 'core_mailing_list_message';
+                                
+                                        options.params.ontable = (_this.data.module) ? _this.data.module + '_mailing_list_message' : 'crm_mailing_list_message';
                                     }
                                 }
                             },
@@ -933,7 +960,9 @@ Pman.Dialog.CoreMailingListMessage = {
                                                 return;
                                             }
                                             
-                                            Pman.Dialog.Image.show( { id : 0, onid: _this.data.id, ontable: 'core_mailing_list_message' }, function() {
+                                            var ontable = (_this.data.module) ? _this.data.module + '_mailing_list_message' : 'crm_mailing_list_message';
+                                            
+                                            Pman.Dialog.Image.show( { id : 0, onid: id, ontable: ontable }, function() {
                                                 _this.igrid.getDataSource().load({});
                                             }); 
                                         }
@@ -1033,8 +1062,8 @@ Pman.Dialog.CoreMailingListMessage = {
                         click : function (_self, e)
                         {
                             //_this.dialog.hide();
-                            
-                            Pman.Dialog.CrmMailingListMessagePreview.show({ id : _this.form.findField('id').getValue() });
+                            Roo.log(_this.data.module);
+                            Pman.Dialog.CoreMailingListMessagePreview.show({ id : _this.form.findField('id').getValue(), module : _this.data.module });
                         },
                         render : function (_self)
                         {
@@ -1054,7 +1083,7 @@ Pman.Dialog.CoreMailingListMessage = {
                             var id = _this.form.findField('id').getValue();
                             
                             if(id*1 < 1){
-                                Roo.MessageBox.alert('Error', 'Please select a queue to send');
+                                Roo.MessageBox.alert('Error', 'Please save the message frist!');
                                 return;
                             }
                            
@@ -1063,8 +1092,7 @@ Pman.Dialog.CoreMailingListMessage = {
                                 method : 'POST',
                                 mask: 'Sending',
                                 params : {
-                                    _id : id,
-                                    _action : 'html'
+                                    _id : id
                                 }, 
                                 success : function(res) { 
                                     if(res.data == 'SUCCESS'){