DataObjects/pman.links.ini
[Pman.Core] / Pman.Dialog.CoreMailingListMessage.js
index 1ca4cc5..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",
@@ -161,6 +161,73 @@ 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,
+                                alwaysQuery : true,
+                                displayField : 'file',
+                                editable : false,
+                                emptyText : "Select Template",
+                                fieldLabel : 'Template',
+                                forceSelection : true,
+                                hiddenName : 'template',
+                                listWidth : 400,
+                                loadingText : "Searching...",
+                                minChars : 2,
+                                name : 'template',
+                                pageSize : 20,
+                                qtip : "Select Template",
+                                selectOnFocus : true,
+                                tpl : '<div class="x-grid-cell-text x-btn button"><b>{file}</b> </div>',
+                                triggerAction : 'all',
+                                typeAhead : true,
+                                valueField : 'file',
+                                width : 200,
+                                store : {
+                                    xtype: 'Store',
+                                    xns: Roo.data,
+                                    listeners : {
+                                        beforeload : function (_self, o){
+                                            o.params = o.params || {};
+                                            // set more here
+                                           
+                                        }
+                                    },
+                                    remoteSort : true,
+                                    sortInfo : { direction : 'DESC', field: 'file' },
+                                    proxy : {
+                                        xtype: 'HttpProxy',
+                                        xns: Roo.data,
+                                        method : 'GET',
+                                        url : baseURL + '/Core/MailTemplateList.php'
+                                    },
+                                    reader : {
+                                        xtype: 'JsonReader',
+                                        xns: Roo.data,
+                                        id : 'name',
+                                        root : 'data',
+                                        totalProperty : 'total',
+                                        fields : [{"name":"file","type":"string"},{"name":"content","type":"string"}]
+                                    }
+                                }
+                            },
                             {
                                 xtype: 'Fill',
                                 xns: Roo.Toolbar
@@ -237,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
@@ -286,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);
@@ -312,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){
@@ -465,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;
                                                                                         }
                                                                                     }
@@ -496,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';
@@ -610,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
@@ -715,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';
                                     }
                                 }
                             },
@@ -883,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({});
                                             }); 
                                         }
@@ -983,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)
                         {
@@ -1004,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;
                             }
                            
@@ -1013,8 +1092,7 @@ Pman.Dialog.CoreMailingListMessage = {
                                 method : 'POST',
                                 mask: 'Sending',
                                 params : {
-                                    _id : id,
-                                    _action : 'html'
+                                    _id : id
                                 }, 
                                 success : function(res) { 
                                     if(res.data == 'SUCCESS'){