Pman.Dialog.CoreEmail.bjs
[Pman.Core] / Pman.Dialog.CoreEmail.js
index 79c5a22..f6b7bda 100644 (file)
@@ -28,6 +28,7 @@ Pman.Dialog.CoreEmail = {
   '396ecabf0cd1f9503e591418851ef406' :"Edit / Create Message",
   'b9c49611cfda3259a2b837b39489e650' :"Add Image",
   'ea4788705e6873b424c65e91c2846b19' :"Cancel",
+  'c4ca4238a0b923820dcc509a6f75849b' :"1",
   'bd88a20b53a47f7b5704a83a15ff5506' :"Saved Version",
   'b20a8b77b05d53b4e695738731400c85' :"Mailout Name",
   '1bd18d39370b7f26c1c5e18067b74c6f' :"Html File",
@@ -546,6 +547,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;
@@ -569,6 +572,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') {
@@ -602,6 +608,36 @@ Pman.Dialog.CoreEmail = {
                xns : Roo.form,
                '|xns' : 'Roo.form',
                xtype : 'TextField'
+              },
+              {
+               hideLabels : true,
+               xns : Roo.form,
+               '|xns' : 'Roo.form',
+               xtype : 'Column',
+               items  : [
+                {
+                 boxLabel : 'Enabled - will be sent out',
+                 checked : true,
+                 name : 'active',
+                 value : 1,
+                 valueOff : 0,
+                 xns : Roo.form,
+                 '|xns' : 'Roo.form',
+                 xtype : 'Checkbox',
+                 listeners : {
+                  check : function (_self, checked)
+                   {
+                       var boxLabel = 'Enabled - will be sent out';
+                       
+                       if(!checked){
+                           boxLabel = 'Disabled - will NOT be sent out right of \'Mailout Name\'';
+                       }
+                       
+                       this.setBoxLabel(boxLabel);
+                   }
+                 }
+                }
+               ]
               }
              ]
             },
@@ -654,6 +690,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',
@@ -699,6 +749,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,
@@ -882,6 +992,7 @@ Pman.Dialog.CoreEmail = {
                      xtype : 'Separator'
                     },
                     {
+                     cls : 'x-init-enable',
                      text : _this._strings['bd88a20b53a47f7b5704a83a15ff5506'] /* Saved Version */,
                      xns : Roo.Toolbar,
                      '|xns' : 'Roo.Toolbar',
@@ -890,6 +1001,7 @@ Pman.Dialog.CoreEmail = {
                       click : function (_self, e)
                        {
                            this.scope.owner.fireEvent('savedpreview', this.scope.owner);
+                           
                        }
                      }
                     }