PHP8
[Pman.BAdmin] / Pman.Tab.BAdminEmailTemplates.js
index 7e938d6..1f28738 100644 (file)
@@ -10,19 +10,17 @@ Pman.Tab.BAdminEmailTemplates = new Roo.XComponent({
   'cdb6b6bab1fd18b9dbfe3fb84a5d34ae' :"<i class=\"fa fa-search\"></i>",
   'cae905999a2ad1dfb8f4eae0e8cda73b' :"From Name<br/>Email",
   '98d2ee61ddce0c7666297d81639914f1' :"To / BCC Group",
-  '694e249c3a9503141fa5ce3fb71d5477' :"<i class=\"fa fa-edit\"></i> Edit",
   '73ea6b4441cdced246d236b22c8f991c' :"HTML File",
+  '694e249c3a9503141fa5ce3fb71d5477' :"<i class=\"fa fa-edit\"></i> Edit",
   'cffbd822c38679e2fbf11cc182c945e5' :"search for email template",
-  'b78a3223503896721cca1303f776159b' :"Title",
-  '68b00d723d37122f64da8d9939f836f0' :"BCC Group",
   '9e11143e29a031212f2cdefcf61f39e9' :"View Message",
   'f49559cda3fb906fbd7736f8b8a0e37d' :"Email Template",
-  'cd6df251f262cc64514b25f04aecf3c8' :"<i class=\"fa fa-clipboard\"></i> Copy",
   '27a7146e1e1890e289bc7fad72876831' :"<i class=\"fa fa-plus\"></i> Create a template",
+  'cd6df251f262cc64514b25f04aecf3c8' :"<i class=\"fa fa-clipboard\"></i> Copy",
   'ed807858fcb68abdd180481f1fcba5c5' :"<i class=\"fa fa-trash\"></i> Delete",
-  'fd5293a712d172f5c556a83c62d44bd6' :"<i class=\"fa fa-plus\"></i> Add",
   '03c2e7e41ffc181a4e84080b4710e81e' :"New",
-  '49ee3087348e8d44e1feda1917443987' :"Name",
+  '4d3d769b812b6faa6b76e1a8abaece2d' :"Active",
+  'b5a7adde1af5c87d7fd797b6245c2a39' :"Description",
   'e6b391a8d2c4d45902a23a8b6585703d' :"URL"
  },
 
@@ -41,6 +39,22 @@ Pman.Tab.BAdminEmailTemplates = new Roo.XComponent({
    xtype : 'Nest',
    background : true,
    title : _this._strings['f49559cda3fb906fbd7736f8b8a0e37d'] /* Email Template */,
+   listeners : {
+    activate : function (_self)
+     {
+         if(!document.getElementsByClassName('email-south-pane')) {
+             return;
+         }
+         
+         document.getElementsByClassName('email-south-pane')[0].classList.remove('disable-pane');
+         
+         if(
+             appDisabled.indexOf('Core.SuperAdmin') * 1 != -1
+         ) {
+             document.getElementsByClassName('email-south-pane')[0].classList.add('disable-pane');
+         }
+     }
+   },
    xns : Roo.bootstrap.panel,
    '|xns' : 'Roo.bootstrap.panel',
    layout : {
@@ -57,6 +71,7 @@ Pman.Tab.BAdminEmailTemplates = new Roo.XComponent({
     south : {
      xtype : 'Region',
      autoScroll : true,
+     cls : 'email-south-pane',
      height : 200,
      hideTabs : true,
      split : true,
@@ -104,19 +119,17 @@ Pman.Tab.BAdminEmailTemplates = new Roo.XComponent({
          items  : [
           {
            xtype : 'NavItem',
-           style : 'width: 100%;',
            xns : Roo.bootstrap,
            '|xns' : 'Roo.bootstrap',
            items  : [
             {
-             xtype : 'Container',
-             style : 'width: 100%;',
+             xtype : 'Element',
              xns : Roo.bootstrap,
              '|xns' : 'Roo.bootstrap',
              items  : [
               {
                xtype : 'Row',
-               style : 'padding: 10px;',
+               cls : 'roo-toolbar',
                xns : Roo.bootstrap,
                '|xns' : 'Roo.bootstrap',
                items  : [
@@ -135,8 +148,14 @@ Pman.Tab.BAdminEmailTemplates = new Roo.XComponent({
                          _this.searchBox = this;
                      },
                     specialkey : function (_self, e)
-                     {
-                         _this.table.footer.onClick('first');
+                     {    
+                          if(e.keyCode == e.ENTER) {
+                             if (_this.table) {
+                                 _this.table.footer.onClick('first'); 
+                             }
+                         
+                         }
+                         
                      }
                    },
                    xns : Roo.bootstrap,
@@ -159,96 +178,21 @@ Pman.Tab.BAdminEmailTemplates = new Roo.XComponent({
                 {
                  xtype : 'Column',
                  md : 8,
+                 style : 'text-align: right;',
                  xns : Roo.bootstrap,
                  '|xns' : 'Roo.bootstrap',
                  items  : [
                   {
                    xtype : 'Button',
-                   html : _this._strings['ed807858fcb68abdd180481f1fcba5c5'] /* <i class="fa fa-trash"></i> Delete */,
-                   style : 'margin-left: 10px; margin-right: 10px; float: right;',
-                   weight : 'primary',
-                   listeners : {
-                    click : function (_self, e)
-                     {
-                         Pman.genericDelete(_this.grid, 'core_email');
-                     },
-                    render : function (_self)
-                     {
-                         _this.delete_btn = this;
-                         
-                         this.hide();
-                     }
-                   },
-                   xns : Roo.bootstrap,
-                   '|xns' : 'Roo.bootstrap'
-                  },
-                  {
-                   xtype : 'Button',
-                   html : _this._strings['cd6df251f262cc64514b25f04aecf3c8'] /* <i class="fa fa-clipboard"></i> Copy */,
-                   style : 'margin-left: 10px; margin-right: 10px; float: right;',
-                   listeners : {
-                    click : function (_self, e)
-                     {
-                         var sel = _this.grid.grid.selModel.getSelected();
-                         if (!sel) {
-                             Roo.MessageBox.alert("Error", "Select a message to copy");
-                             return;
-                         }
-                         new Pman.Request({
-                             url : baseURL + '/Roo/Core_email',
-                             method : 'POST',
-                             params : {
-                                 id : sel.data.id,
-                                 _make_copy : 1
-                             },
-                             success : function() {
-                                 _this.table.footer.onClick('refresh');
-                             }
-                         });
-                     },
-                    render : function (_self)
-                     {
-                         _this.copy_btn = this;
-                         
-                         this.hide();
-                     }
-                   },
-                   xns : Roo.bootstrap,
-                   '|xns' : 'Roo.bootstrap'
-                  },
-                  {
-                   xtype : 'Button',
-                   html : _this._strings['694e249c3a9503141fa5ce3fb71d5477'] /* <i class="fa fa-edit"></i> Edit */,
-                   style : 'margin-left: 10px; margin-right: 10px; float: right;',
+                   cls : 'roo-toolbar-button',
+                   html : _this._strings['27a7146e1e1890e289bc7fad72876831'] /* <i class="fa fa-plus"></i> Create a template */,
                    listeners : {
-                    click : function (_self, e)
-                     {
-                         var sel = _this.grid.grid.selModel.getSelected();
-                         
-                         if (!sel || sel.data.id * 1 < 1) {
-                             Roo.MessageBox.alert("Error", "Select a message to edit");
-                             return;
-                         }
-                         
-                         Pman.Dialog.BAdminEmail.show( {id : sel.data.id, module : 'core_email'} , function() {
-                             _this.table.footer.onClick('first');
-                         }); 
-                     },
                     render : function (_self)
                      {
-                         _this.edit_btn = this;
-                         
                          this.hide();
                      }
                    },
                    xns : Roo.bootstrap,
-                   '|xns' : 'Roo.bootstrap'
-                  },
-                  {
-                   xtype : 'Button',
-                   html : _this._strings['27a7146e1e1890e289bc7fad72876831'] /* <i class="fa fa-plus"></i> Create a template */,
-                   style : 'margin-left: 10px; margin-right: 10px; float: right;',
-                   xns : Roo.bootstrap,
                    '|xns' : 'Roo.bootstrap',
                    menu : {
                     xtype : 'Menu',
@@ -324,86 +268,30 @@ Pman.Tab.BAdminEmailTemplates = new Roo.XComponent({
                      }
                     ]
                    }
-                  }
-                 ]
-                }
-               ]
-              }
-             ]
-            }
-           ]
-          },
-          {
-           xtype : 'NavItem',
-           xns : Roo.bootstrap,
-           '|xns' : 'Roo.bootstrap',
-           items  : [
-            {
-             xtype : 'Element',
-             xns : Roo.bootstrap,
-             '|xns' : 'Roo.bootstrap',
-             items  : [
-              {
-               xtype : 'Row',
-               cls : 'roo-toolbar',
-               xns : Roo.bootstrap,
-               '|xns' : 'Roo.bootstrap',
-               items  : [
-                {
-                 xtype : 'Column',
-                 md : 4,
-                 xns : Roo.bootstrap,
-                 '|xns' : 'Roo.bootstrap',
-                 items  : [
-                  {
-                   xtype : 'Input',
-                   placeholder : _this._strings['cffbd822c38679e2fbf11cc182c945e5'] /* search for email template */,
-                   listeners : {
-                    render : function (_self)
-                     {
-                         _this.searchBox = this;
-                     },
-                    specialkey : function (_self, e)
-                     {
-                         _this.table.footer.onClick('first');
-                     }
-                   },
-                   xns : Roo.bootstrap,
-                   '|xns' : 'Roo.bootstrap',
-                   after : {
-                    xtype : 'Button',
-                    html : _this._strings['cdb6b6bab1fd18b9dbfe3fb84a5d34ae'] /* <i class="fa fa-search"></i> */,
-                    listeners : {
-                     click : function (_self, e)
-                      {
-                          _this.table.footer.onClick('first');
-                      }
-                    },
-                    xns : Roo.bootstrap,
-                    '|xns' : 'Roo.bootstrap'
-                   }
-                  }
-                 ]
-                },
-                {
-                 xtype : 'Column',
-                 md : 12,
-                 xns : Roo.bootstrap,
-                 '|xns' : 'Roo.bootstrap',
-                 items  : [
+                  },
                   {
                    xtype : 'Button',
                    cls : 'roo-toolbar-button',
-                   html : _this._strings['fd5293a712d172f5c556a83c62d44bd6'] /* <i class="fa fa-plus"></i> Add */,
-                   weight : 'default',
+                   html : _this._strings['694e249c3a9503141fa5ce3fb71d5477'] /* <i class="fa fa-edit"></i> Edit */,
                    listeners : {
                     click : function (_self, e)
                      {
-                         Pman.Dialog.BAdminCompany.show({}, function() {
-                             if (_this.table) {
-                                 _this.table.footer.onClick('first');
-                             }
+                         var sel = _this.grid.grid.selModel.getSelected();
+                         
+                         if (!sel || sel.data.id * 1 < 1) {
+                             Roo.MessageBox.alert("Error", "Select a message to edit");
+                             return;
+                         }
+                         
+                         Pman.Dialog.BAdminEmail.show( {id : sel.data.id, module : 'core_email'} , function() {
+                             _this.table.footer.onClick('first');
                          }); 
+                     },
+                    render : function (_self)
+                     {
+                         _this.edit_btn = this;
+                         
+                         this.hide();
                      }
                    },
                    xns : Roo.bootstrap,
@@ -412,31 +300,30 @@ Pman.Tab.BAdminEmailTemplates = new Roo.XComponent({
                   {
                    xtype : 'Button',
                    cls : 'roo-toolbar-button',
-                   html : _this._strings['694e249c3a9503141fa5ce3fb71d5477'] /* <i class="fa fa-edit"></i> Edit */,
-                   weight : 'default',
+                   html : _this._strings['cd6df251f262cc64514b25f04aecf3c8'] /* <i class="fa fa-clipboard"></i> Copy */,
                    listeners : {
                     click : function (_self, e)
                      {
-                         var s = _this.table.getSelectionModel().getSelected();
-                             
-                         if (!s || s.data.id * 1 < 1)  {
-                             Roo.bootstrap.MessageBox.alert("Error", 'Please select a company');
+                         var sel = _this.grid.grid.selModel.getSelected();
+                         if (!sel) {
+                             Roo.MessageBox.alert("Error", "Select a message to copy");
                              return;
                          }
-                         
-                         Pman.Dialog.BAdminCompany.show({
-                             id : s.data.id
-                         }, function() {
-                             if (_this.table) {
+                         new Pman.Request({
+                             url : baseURL + '/Roo/Core_email',
+                             method : 'POST',
+                             params : {
+                                 id : sel.data.id,
+                                 _make_copy : 1
+                             },
+                             success : function() {
                                  _this.table.footer.onClick('refresh');
                              }
                          });
-                         
-                         
                      },
                     render : function (_self)
                      {
-                         _this.edit_btn = this;
+                         _this.copy_btn = this;
                          
                          this.hide();
                      }
@@ -452,7 +339,7 @@ Pman.Tab.BAdminEmailTemplates = new Roo.XComponent({
                    listeners : {
                     click : function (_self, e)
                      {
-                         Pman.genericDelete(_this.grid, 'core_company'); 
+                         Pman.genericDelete(_this.grid, 'core_email');
                      },
                     render : function (_self)
                      {
@@ -478,11 +365,35 @@ Pman.Tab.BAdminEmailTemplates = new Roo.XComponent({
       },
       grid : {
        xtype : 'Table',
+       cellSelection : true,
        hover : true,
        loadMask : true,
-       responsive : true,
        rowSelection : true,
        listeners : {
+        cellclick : function (_self, el, rowIndex, columnIndex, e)
+         {
+             var di = this.colModel.getDataIndex(columnIndex);
+             
+              if(di != 'active'){
+                  return;
+              }
+              
+              var r = this.store.getAt(rowIndex);
+              
+             if(r.data.active * 1  < 1){
+             
+                 Pman.Dialog.BAdminEmail.show( {id : r.data.id, module : 'core_email'} , function() {
+                     _this.table.footer.onClick('refresh');
+                 });
+                 
+                 return;
+             }
+             
+             r.set('active', 0);
+             r.commit();
+             
+              
+         },
         render : function (_self)
          {
              
@@ -501,7 +412,7 @@ Pman.Tab.BAdminEmailTemplates = new Roo.XComponent({
              
              _this.dialog.show( {id : data.id, module : 'core_email'} , function() {
                  
-                 _this.table.footer.onClick('first');
+                 _this.table.footer.onClick('refresh');
              }); 
          }
        },
@@ -517,10 +428,14 @@ Pman.Tab.BAdminEmailTemplates = new Roo.XComponent({
        store : {
         xtype : 'Store',
         remoteSort : true,
-        sortInfo : {field:'name',direction:'ASC'},
+        sortInfo : {field:'description',direction:'ASC'},
         listeners : {
          beforeload : function (_self, options)
           {
+              if (!Pman.buildCompleted) {
+                  return false;
+              }
+              
               options.params = options.params || {};
               
               var s = _this.searchBox.getValue();
@@ -528,6 +443,10 @@ Pman.Tab.BAdminEmailTemplates = new Roo.XComponent({
               if(s.length){
                   options.params['search[nameortitle]'] = s;
               }
+              // hide our system emails.
+              if (appDisabled.indexOf('Core.SuperAdmin') > -1) {
+                  options.params._hide_system_emails = 1;
+              } 
           
           },
          load : function (_self, records, options)
@@ -535,6 +454,24 @@ Pman.Tab.BAdminEmailTemplates = new Roo.XComponent({
               _this.edit_btn.hide();
               _this.copy_btn.hide();
               _this.delete_btn.hide();
+          },
+         update : function (_self, record, operation)
+          {
+              if (operation != 'commit') {
+                  return;
+              }
+          
+              new Pman.Request({
+                  url : baseURL + '/Roo/Core_email',
+                  method : 'POST',
+                  params : {
+                    id : record.data.id,
+                    active : record.data.active
+                  },
+                  success : function() { 
+                      _this.table.footer.onClick('refresh');
+                  }
+            });
           }
         },
         xns : Roo.data,
@@ -556,6 +493,10 @@ Pman.Tab.BAdminEmailTemplates = new Roo.XComponent({
              {
                  "name":"subject",
                  "type":"string"
+             },
+             {
+                 "name":"description",
+                 "type":"string"
              }
          ],
          id : 'id',
@@ -596,39 +537,40 @@ Pman.Tab.BAdminEmailTemplates = new Roo.XComponent({
        cm : [
         {
          xtype : 'ColumnModel',
+         align : 'center',
          cursor : 'pointer',
-         dataIndex : 'name',
-         header : _this._strings['49ee3087348e8d44e1feda1917443987'] /* Name */,
-         renderer : function(v,x,r) 
-         { 
-             if(r.data.active * 1 < 1){
-             
-                 return String.format('<span style="font-size:12px;"><s>{0}</s><span>', v ? v : ''); 
-                 
-             }
+         dataIndex : 'active',
+         header : _this._strings['4d3d769b812b6faa6b76e1a8abaece2d'] /* Active */,
+         renderer : function(v) {  
+         
+             var state = v > 0 ?  'check-' : '';
+             var cls = v > 0 ? 'text-primary' : '';
              
-             return String.format('<span style="font-size:12px;">{0}<span>', v ? v : ''); 
-         },
+             return '<i class=\"far fa-'+ state + 'square-o ' + cls + '\" aria-hidden=\"true\"></i>';
+                         
+          },
          sortable : true,
-         xs : 3,
+         xs : 1,
          xns : Roo.grid,
          '|xns' : 'Roo.grid'
         },
         {
          xtype : 'ColumnModel',
          cursor : 'pointer',
-         dataIndex : 'subject',
-         header : _this._strings['b78a3223503896721cca1303f776159b'] /* Title */,
+         dataIndex : 'description',
+         header : _this._strings['b5a7adde1af5c87d7fd797b6245c2a39'] /* Description */,
          renderer : function(v,x,r) 
          { 
+             vv = (v.length) ? v : r.data.name;
+             
              if(r.data.active * 1 < 1){
-                 return String.format('<span style="font-size:12px;"><s>{0}</s></span>', v ? v : ''); 
+                 return '<small style="color: #999;">' + vv + '</small>';
              }
              
-             return String.format('<span style="font-size:12px;">{0}</span>', v ? v : ''); 
+             return '<b>' + vv + '</b>';
          },
          sortable : true,
-         xs : 3,
+         xs : 4,
          xns : Roo.grid,
          '|xns' : 'Roo.grid'
         },
@@ -639,22 +581,12 @@ Pman.Tab.BAdminEmailTemplates = new Roo.XComponent({
          header : _this._strings['cae905999a2ad1dfb8f4eae0e8cda73b'] /* From Name<br/>Email */,
          renderer : function(v,x,r)
          {
-             var from_name = r.data.from_name ? r.data.from_name : '';
-             var from_email = r.data.from_email ? r.data.from_email : '';
-             
-             //var r = from_name + '<br>' + from_email ;
-             if(from_name =='') {
-                 return String.format('<span style="font-size:12px;">{0}</span>', from_email);
+             if(r.data.active * 1 < 1){
+                 return '';
              }
-             return String.format('<span style="font-size:12px;">{0} <br> {1}</span>', from_name, from_email);
              
-             /*
-             return String.format(
-                 '{0}'+'<'+'{1}'+'>',
-                 r.data.from_name ? r.data.from_name : '',
-                 r.data.from_email ? r.data.from_email : ''
-             );
-             */
+             return String.format('<small>{0}</small>', r.data.from_name );
+             
          },
          xs : 3,
          xns : Roo.grid,
@@ -667,27 +599,36 @@ Pman.Tab.BAdminEmailTemplates = new Roo.XComponent({
          header : _this._strings['98d2ee61ddce0c7666297d81639914f1'] /* To / BCC Group */,
          renderer : function(v,x,r)
          { 
-             if(r.data.group_member_count * 1 < 1 && r.data.to_group_name !=''){
-                 return String.format('<span style="font-size:12px;">To: {0} <span class="text-danger">(0)</span> <br>BCC: {1}</span>', r.data.to_group_name ,r.data.bcc_group_name ); 
+             if(r.data.active * 1 < 1){
+                 return '';
              }
-             if(r.data.to_group_name ==''){
-                 return String.format('<span style="font-size:12px;">BCC: {0}</span>', r.data.bcc_group_name ); 
+             
+             var nid = r.data.to_group_id * 1 ;
+             var n = nid > 0 ? r.data.group_member_count * 1 : 0;
+             var grp_str = String.format('<small>To: {0} ' + 
+                     '<span class="badge' + (n > 0 ?  '' : ' badge-danger') + '">{1}</span></small><br>',
+                     r.data.to_group_id_name,
+                     nid < 1 ? 'Not set' : n
+                 );
+            
+             if (nid < 0) { // no To needed..
+                 grp_str = '';
              }
+             nid = r.data.bcc_group_id * 1;
+             n = nid > 0 ? r.data.bcc_group_member_count * 1 : 0;
          
-             return String.format('<span style="font-size:12px;">To: {0} <br>BCC: {1}</span>', r.data.to_group_name,r.data.bcc_group_name ); 
+             var bcc_str = String.format('<small>BCC: {0} <span class="badge' + (n > 0 ?  '' : ' badge-danger') + '">{1}</span></small>',
+                     r.data.bcc_group_id_name,
+                     nid < 1 ? 'Not set' : n
+                 );
+                 
+             if (nid < 0) { // no To needed..
+                 bcc_str = '';
+             }  
+             
+             return grp_str + bcc_str;
          },
-         xs : 3,
-         xns : Roo.grid,
-         '|xns' : 'Roo.grid'
-        },
-        {
-         xtype : 'ColumnModel',
-         cursor : 'pointer',
-         dataIndex : 'bcc_group_name',
-         header : _this._strings['68b00d723d37122f64da8d9939f836f0'] /* BCC Group */,
-         hidden : true,
-         renderer : function(v) { return String.format('{0}', v ? v : ''); },
-         xs : 2,
+         xs : 4,
          xns : Roo.grid,
          '|xns' : 'Roo.grid'
         }