DataObjects/Core_domain.php
[Pman.Core] / Pman.Dialog.CoreEmail.js
index 1ca108a..69318ef 100644 (file)
@@ -28,15 +28,16 @@ Pman.Dialog.CoreEmail = {
   '396ecabf0cd1f9503e591418851ef406' :"Edit / Create Message",
   'b9c49611cfda3259a2b837b39489e650' :"Add Image",
   'ea4788705e6873b424c65e91c2846b19' :"Cancel",
+  'bd88a20b53a47f7b5704a83a15ff5506' :"Saved Version",
   'b20a8b77b05d53b4e695738731400c85' :"Mailout Name",
   '1bd18d39370b7f26c1c5e18067b74c6f' :"Html File",
   '5da618e8e4b89c66fe86e32cdafde142' :"From",
   '31bb2f6e9b8fb11cbb7fb63c6025223f' :"Select Template",
   'b78a3223503896721cca1303f776159b' :"Title",
   '278c491bdd8a53618c149c4ac790da34' :"Template",
-  'c9cc8cce247e49bae79f15173ce97354' :"Save",
   '1351017ac6423911223bc19a8cb7c653' :"Filename",
   '308f2757bfc9ce92fb00ff93fdffd279' :"Images / Attachments",
+  'c9cc8cce247e49bae79f15173ce97354' :"Save",
   '5feb9bf3c03b32635135006cbacb9542' :"Insert Field",
   '4c2a8fe7eaf24721cc7a9f0175115bd4' :"Message",
   'fff0d600f8a0b5e19e88bfb821dd1157' :"Images"
@@ -301,7 +302,7 @@ Pman.Dialog.CoreEmail = {
                       method: 'POST',
                       mask : "Loading",
                       params : {
-                            importUrl : l.protocol +'//' + l.host +   rootURL + '/Pman/Crm/mail_templates/responsive1.html',
+                            importUrl : l.protocol +'//' + l.host +   rootURL + '/Pman/Crm/mail_templates/responsive1.html'
                      },
                       success : function (res) {
               
@@ -471,6 +472,13 @@ Pman.Dialog.CoreEmail = {
            preValidate : function(done_callback) {
                
                Roo.MessageBox.progress("Uploading Images", "Uploading");
+               
+               if(!_this.form.findField('bodytext').editorcore.sourceEditMode){
+                   _this.form.findField('bodytext').syncValue();
+               }else{
+                   _this.form.findField('bodytext').pushValue();
+               }
+               
                var html = _this.form.findField('bodytext').getValue();
                
                var s = Roo.get(_this.form.findField('bodytext').editorcore.doc.documentElement);
@@ -500,7 +508,7 @@ Pman.Dialog.CoreEmail = {
                        return;
                    }
                    
-                   n = i.getAttribute('src').match(/^http(.*)/)
+                   n = i.getAttribute('src').match(/^http(.*)/);
                   
                    if(!n ){
                        mkimg();
@@ -538,6 +546,8 @@ Pman.Dialog.CoreEmail = {
                 
                  if (action.type == 'setdata') {
                  
+                     setInterval(_this.form.findField('bodytext').autosave, 5000);
+                     
                      _this.data.module = _this.data.module || 'crm_mailing_list_message';
                      
                      _this.form.url = baseURL + '/Roo/' + _this.data.module;
@@ -561,6 +571,9 @@ Pman.Dialog.CoreEmail = {
                  }
                  if (action.type == 'load') {
                      _this.dialog.el.unmask();
+                     
+                     _this.form.findField('bodytext').originalValue = _this.form.findField('bodytext').getValue();
+                     
                      return;
                  }
                  if (action.type =='submit') {
@@ -646,6 +659,20 @@ Pman.Dialog.CoreEmail = {
                xtype : 'FieldSet',
                items  : [
                 {
+                 autosave : function() {
+                     
+                     var body = _this.form.findField('bodytext');
+                     
+                     if(!body.wrap.isVisible(true) || body.getValue() == '' || !body.isDirty()){
+                         Roo.log('body not dirty');
+                         return;
+                     }
+                     
+                     Roo.log('body dirty, auto save!');
+                     
+                     body.fireEvent('autosave', body);
+                    
+                 },
                  clearUp : false,
                  cwhite : [ 
                      'margin',
@@ -683,7 +710,7 @@ Pman.Dialog.CoreEmail = {
                      'vertical-align',
                      'cursor',
                      'z-index',
-                     'right',
+                     'right'
                   ],
                  height : 250,
                  name : 'bodytext',
@@ -691,6 +718,66 @@ Pman.Dialog.CoreEmail = {
                  xns : Roo.form,
                  '|xns' : 'Roo.form',
                  xtype : 'HtmlEditor',
+                 listeners : {
+                  autosave : function (_self)
+                   {
+                       Roo.log('autosave');
+                       
+                       var id = _this.form.findField('id').getValue() * 1;
+                       
+                       /*
+                       if(!_self.editorcore.sourceEditMode){
+                           _self.syncValue();
+                       }else{
+                           _self.pushValue();
+                       }
+                       */
+                       
+                       new Pman.Request({
+                           url : baseURL + '/Roo/Events.php',
+                           method :'POST',
+                           params : {
+                               id : 0,
+                               action : 'AUTOSAVE',
+                               on_id : (id > 0) ? id : 0,
+                               on_table : 'crm_mailing_list_message',
+                               remarks : 'BODY',
+                               source: _self.getValue()
+                           },
+                           success : function() {
+                               _self.originalValue = _self.getValue();
+                               
+                           },
+                           failure : function() 
+                           {
+                               Roo.log('body autosave failed?!');
+                           }
+                       });
+                       
+                   },
+                  savedpreview : function (_self)
+                   {
+                       var id = _this.form.findField('id').getValue() * 1;
+                       
+                       var successFn = function(res){
+                           return res.data.POST.source;
+                       };
+                       
+                       var params = {
+                           action : 'AUTOSAVE',
+                           remarks : 'BODY',
+                           on_id : (id < 1) ? 0 : id,
+                           on_table : 'crm_mailing_list_message',
+                           successFn : successFn
+                       };
+                       
+                       
+                       Pman.Dialog.CoreAutoSavePreview.show(params, function(res){
+                           _self.setValue(res);
+                           _self.originalValue = res;
+                       });
+                   }
+                 },
                  toolbars : [
                   {
                    xns : Roo.form.HtmlEditor,
@@ -744,7 +831,7 @@ Pman.Dialog.CoreEmail = {
                            }).defer(100);
                            var editor = _this.form.findField('bodytext').editorcore;
                            
-                           var curnode = editor.getSelectedNode()
+                           var curnode = editor.getSelectedNode();
                            if (curnode && curnode.tagName == 'IMG') {
                                curnode.src= String.format('{0}/Images/{1}/{2}#image-{1}',
                                        baseURL,  record.data.id, record.data.filename
@@ -778,7 +865,7 @@ Pman.Dialog.CoreEmail = {
                                 Roo.MessageBox.alert("Error", "Save email template first");
                                 return false;
                             }
-                            o.params.onid = id
+                            o.params.onid = id;
                             o.params.ontable = (_this.data.module) ? _this.data.module : 'crm_mailing_list_message';
                             
                            // o.params.imgtype = 'PressRelease';
@@ -867,6 +954,25 @@ Pman.Dialog.CoreEmail = {
                       '|xns' : 'Roo.data',
                       xtype : 'SimpleStore'
                      }
+                    },
+                    {
+                     xns : Roo.Toolbar,
+                     '|xns' : 'Roo.Toolbar',
+                     xtype : 'Separator'
+                    },
+                    {
+                     cls : 'x-init-enable',
+                     text : _this._strings['bd88a20b53a47f7b5704a83a15ff5506'] /* Saved Version */,
+                     xns : Roo.Toolbar,
+                     '|xns' : 'Roo.Toolbar',
+                     xtype : 'Button',
+                     listeners : {
+                      click : function (_self, e)
+                       {
+                           this.scope.owner.fireEvent('savedpreview', this.scope.owner);
+                           
+                       }
+                     }
                     }
                    ]
                   }