DataObjects/Core_notify.php
[Pman.Core] / Pman.js
diff --git a/Pman.js b/Pman.js
index 05e45d4..6210427 100644 (file)
--- a/Pman.js
+++ b/Pman.js
@@ -8,11 +8,17 @@
  * 
  * {tag: 'div', style: 'display:block;position:absolute;top:2;left:300;width:100%;height:25px'});
  * 
+ * 
+ *  CHANGES
+ *  - gtranslate moved to Pman.GoogleTranslate
+ * 
+ * 
  */
  
 if (typeof(_T) == 'undefined') { _T={};}
  
 
+
   
 
 Pman = new Roo.Document(
@@ -37,16 +43,16 @@ Pman = new Roo.Document(
             }
             
             // remove loader..
-            if (Ext.get('loading')) {
-                Ext.get('loading').remove();
+            if (Roo.get('loading')) {
+                Roo.get('loading').remove();
             }
             
-            Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
+            Roo.state.Manager.setProvider(new Roo.state.CookieProvider());
             
             // link errors...
             
             if (AppLinkError.length) {
-                Ext.MessageBox.alert("Error", AppLinkError, function() {
+                Roo.MessageBox.alert("Error", AppLinkError, function() {
                     Pman.Login.onLoad();
                 });
                 return;
@@ -97,18 +103,18 @@ Pman = new Roo.Document(
         if (this.layout) {
             return; // already loaded
         } 
-        if (Ext.get('loading')) {
-            Ext.get('loading').remove();
+        if (Roo.get('loading')) {
+            Roo.get('loading').remove();
         }
-        if (Ext.get('loading-mask')) {
-            Ext.get('loading-mask').show();
+        if (Roo.get('loading-mask')) {
+            Roo.get('loading-mask').show();
         }
         
         
        
         
         /*
-        Ext.MessageBox.show({
+        Roo.MessageBox.show({
            title: "Please wait...",
            msg: "Building Interface...",
            width:340,
@@ -118,7 +124,7 @@ Pman = new Roo.Document(
         });
         */
         //Pman.onLoadBuild();
-        //Ext.get(document.body).mask("Building Interface");
+        //Roo.get(document.body).mask("Building Interface");
         //Pman.onLoadBuild.defer(100, Pman);
        //Pman.onLoadBuild();
                     
@@ -127,7 +133,7 @@ Pman = new Roo.Document(
         
         var _this = this;
         this.stime = new Date();
-        this.layout = new Ext.BorderLayout(document.body, {
+        this.layout = new Roo.BorderLayout(document.body, {
             north: {
                 split:false,
                 initialSize: 25,
@@ -143,13 +149,15 @@ Pman = new Roo.Document(
                 //resizeTabs: true,
                 alwaysShowTabs: true,
                 minTabWidth: 140
-            } /*,
+            } ,
             south: {
+                collapsible : true,
+                collapsed : true,
                 split:false,
-                initialSize: 25,
+                height: 120,
                 titlebar: false
             }
-            */
+            
         });
         
         this.fireEvent('beforeload',this);
@@ -157,20 +165,20 @@ Pman = new Roo.Document(
         
         
         this.layout.beginUpdate();
-        this.layout.add('north', new Ext.ContentPanel('title', 'North'));
+        this.layout.add('north', new Roo.ContentPanel('title', 'North'));
         var au = Pman.Login.authUser;
-        if (au.id > 0 && au.company_id_background_color.length) {
-            Ext.get('title').dom.style.backgroundColor = '#' + au.company_id_background_color;
-            Ext.get('headerInformation').dom.style.color = this.invertColor('#' + au.company_id_background_color);
+        if (au.id > 0 && au.company_id_background_color && au.company_id_background_color.length) {
+            Roo.get('title').dom.style.backgroundColor = '#' + au.company_id_background_color;
+            Roo.get('headerInformation').dom.style.color = this.invertColor('#' + au.company_id_background_color);
         }
         if (au.id > 0 && au.company_id_logo_id * 1 > 0) {
-            Ext.get('headerInformation-company-logo').dom.src =  baseURL + 
+            Roo.get('headerInformation-company-logo').dom.src =  baseURL + 
                 '/Images/' + au.company_id_logo_id + '/' + au.company_id_logo_id_filename;
         } else {
-            Ext.get('headerInformation-company-logo').dom.src = Roo.BLANK_IMAGE_URL;
+            Roo.get('headerInformation-company-logo').dom.src = Roo.BLANK_IMAGE_URL;
         }
         
-        Ext.get('headerInformation').dom.innerHTML = String.format(
+        Roo.get('headerInformation').dom.innerHTML = String.format(
                 "You are Logged in as <b>{0} ({1})</b>", // to {4} v{3}", // for <b>{2}</b>",
                 au.name, au.email, au.company_id_name, 
                 AppVersion , appNameShort
@@ -178,13 +186,13 @@ Pman = new Roo.Document(
         
         
         document.title = appName + ' v' + AppVersion + ' - ' + au.company_id_name;
-        Ext.QuickTips.init(); 
-        if (Ext.isGecko) {
-           Ext.useShims = true;
+        Roo.QuickTips.init(); 
+        if (Roo.isGecko) {
+           Roo.useShims = true;
         }
        
         //this.mainLayout.beginUpdate();
-        //var maskDom = Ext.get(document.body)._maskMsg.dom
+        //var maskDom = Roo.get(document.body)._maskMsg.dom
         this.layout.beginUpdate();
         
         Pman.building = true;
@@ -216,14 +224,14 @@ Pman = new Roo.Document(
         var tbh = se.createChild( 
                 { tag: 'td', style: 'width:100%;'  });
         
-        var lotb = new Ext.Toolbar(tbh);
+        var lotb = new Roo.Toolbar(tbh);
         
         if (Roo.isSafari) {
             var tbl = se.child('table', true);
             tbl.setAttribute('width', '100%');
         }
         lotb.add(
-            new Ext.Toolbar.Fill(), 
+            new Roo.Toolbar.Fill(), 
      
             {
                 text: "Change Password",
@@ -260,7 +268,7 @@ Pman = new Roo.Document(
                      
                     text: "Add New Item",
                     cls: 'x-btn-text-icon',
-                    icon: Ext.rootURL + 'images/default/dd/drop-add.gif',
+                    icon: Roo.rootURL + 'images/default/dd/drop-add.gif',
                     menu : {
                         items : this.subMenuItems
                     }     
@@ -302,9 +310,9 @@ Pman = new Roo.Document(
             
         };
         
-        Ext.MessageBox.hide();
-        if (Ext.get('loading-mask')) {
-           Ext.get('loading-mask').remove();
+        Roo.MessageBox.hide();
+        if (Roo.get('loading-mask')) {
+           Roo.get('loading-mask').remove();
         }
         
         
@@ -321,10 +329,11 @@ Pman = new Roo.Document(
         var forceAdmin = function(data)
         {
             if (!data || !data.id) {
+                //Roo.log("Force Admin");
                 Pman.Dialog.PersonStaff.show( 
                     { 
                         id : 0, 
-                        company_id : Pman.Login.authUser.company_id * 1, 
+                        company_id : Pman.Login.authUser.company_id_id * 1, 
                         company_id_name : Pman.Login.authUser.company_id_name
                     }, function(data) {
                         forceAdmin(data);
@@ -332,7 +341,7 @@ Pman = new Roo.Document(
                 );
                 return;
             }
-            Ext.state.Manager.set('Pman.Login.username', data.email),
+            Roo.state.Manager.set('Pman.Login.username', data.email),
             window.onbeforeunload = false;
             document.location = baseURL + '?ts=' + Math.random();
         }
@@ -348,12 +357,19 @@ Pman = new Roo.Document(
                 });
                 return;
             }
+            Pman.Login.authUser.company_id_id  = data.id;
             Pman.Login.authUser.company_id  = data.id;
             Pman.Login.authUser.company_id_name  = data.name;
             forceAdmin();
         }
         
         if (Pman.Login.authUser.id < 0) {
+            // admin company has been created - create the user..
+            if (Pman.Login.authUser.company_id_id* 1 > 0) {
+                forceAdmin();
+                return;
+            }
+            
             forceCompany();
             /// create account..
             
@@ -379,7 +395,7 @@ Pman = new Roo.Document(
     
     
     onLoadTrackCall : function(id,cb, cls) {
-        Ext.get(document.body).mask("Loading Document details");
+        Roo.get(document.body).mask("Loading Document details");
 
         Pman.request({
             url: baseURL + '/Roo/Documents.html',  
@@ -388,7 +404,7 @@ Pman = new Roo.Document(
             },  
             method: 'GET',  
             success : function(data) {
-                Ext.get(document.body).unmask();
+                Roo.get(document.body).unmask();
              
                 
                 switch(data.in_out) {
@@ -396,14 +412,14 @@ Pman = new Roo.Document(
                     case 'OUT' : cls+='Out';break;
                     case 'WIP' : cls+='Wip';break;
                     default: 
-                        Ext.MessageBox.alert("Error", "invalid in_out");
+                        Roo.MessageBox.alert("Error", "invalid in_out");
                         return;
                 }
                 Pman.Dialog[cls].show(data, cb ? cb : Pman.refreshActivePanel);
             }, 
             
             failure: function() {
-                Ext.get(document.body).unmask();
+                Roo.get(document.body).unmask();
                 //if (cb) {
                 //    cb.call(false);
                 //}
@@ -445,7 +461,7 @@ Pman = new Roo.Document(
     {
         var res = '';
         try {
-            res = Ext.decode(response.responseText);
+            res = Roo.decode(response.responseText);
             // oops...
             if (typeof(res) != 'object') {
                 res = { success : false, errorMsg : res, errors : true };
@@ -466,7 +482,7 @@ Pman = new Roo.Document(
             
         var s = tab.grid.getSelectionModel().getSelections();
         if (!s.length)  {
-            Ext.MessageBox.alert("Error", "Select at least one Row to delete" );
+            Roo.MessageBox.alert("Error", "Select at least one Row to delete" );
             return '';
         }
         
@@ -474,7 +490,7 @@ Pman = new Roo.Document(
             r.push(s[i].data.id);
         }
     
-        Ext.MessageBox.confirm("Confirm", "Are you sure you want to delete that?",
+        Roo.MessageBox.confirm("Confirm", "Are you sure you want to delete that?",
             function(btn) {
                 if (btn != 'yes') {
                     return;
@@ -505,7 +521,7 @@ Pman = new Roo.Document(
                     },
                     failure: function(act) {
                         tab.grid.getView().mainWrap.unmask();
-                        Ext.MessageBox.alert("Error", "Error Deleting");
+                        Roo.MessageBox.alert("Error", "Error Deleting");
                     }
                     
                 });
@@ -532,28 +548,28 @@ Pman = new Roo.Document(
     standardActionFailed :  function(f, act, cb) {
     
         if (act.failureType == 'client') {
-            Ext.MessageBox.alert("Error", "Please Correct all the errors in red", cb);
+            Roo.MessageBox.alert("Error", "Please Correct all the errors in red", cb);
             return;
         }
         if (act.failureType == 'connect') {
-            Ext.MessageBox.alert("Error", "Problem Connecting to Server - please try again.", cb);
+            Roo.MessageBox.alert("Error", "Problem Connecting to Server - please try again.", cb);
             return;
         }
         
         if (act.type == 'submit') {
             
-            Ext.MessageBox.alert("Error", typeof(act.result.errorMsg) == 'string' ?
+            Roo.MessageBox.alert("Error", typeof(act.result.errorMsg) == 'string' ?
                 String.format('{0}', act.result.errorMsg) : 
                 "Saving failed = fix errors and try again", cb);
             return;
         }
         
         // what about load failing..
-        Ext.MessageBox.alert("Error", "Error loading details",cb); 
+        Roo.MessageBox.alert("Error", "Error loading details",cb); 
     },
     /**
      * 
-     * similar to Ext.Ajax, but handles our responses better...
+     * similar to Roo.Ajax, but handles our responses better...
      * c.url
      * c.method
      * c.params
@@ -563,9 +579,10 @@ Pman = new Roo.Document(
      * 
      */
     request : function(c) {
-        
-        Ext.Ajax.request({
-            timeout : c.timeout || 30000,
+        var r= new Roo.data.Connection({
+            timeout : typeof(c.timeout) == 'undefined' ?  30000 : c.timeout
+        });
+        r.request({
             url: c.url,
             method : c.method,
             params: c.params,
@@ -581,7 +598,7 @@ Pman = new Roo.Document(
                         }
                     }
                     Roo.MessageBox.hide();
-                    Ext.MessageBox.alert("Error", res.errorMsg ? res.errorMsg : "Error Sending");
+                    Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg : "Error Sending");
                     return;
                 }
                 
@@ -598,81 +615,23 @@ Pman = new Roo.Document(
                 }
                 Roo.MessageBox.hide();
                 Roo.MessageBox.alert("Error", "Connection timed out sending");
-                console.log(response);
+                Roo.log(response);
                 
             },
             scope: this
             
         });
     },
-    csvFrame : false,
     
-    createCsvFrame: function()
-    {
-        
-        if (this.csvFrame) {
-            document.body.removeChild(this.csvFrame);
-        }
-            
-        var id = Ext.id();
-        this.csvFrame = document.createElement('iframe');
-        this.csvFrame.id = id;
-        this.csvFrame.name = id;
-        this.csvFrame.className = 'x-hidden';
-        if(Ext.isIE){
-            this.csvFrame.src = Ext.SSL_SECURE_URL;
-        }
-        document.body.appendChild(this.csvFrame);
-
-        if(Ext.isIE){
-            document.frames[id].name = id;
-        }
-        
-    },
-    /**
-     * download({
-          url: 
-         })
-     * 
-     * 
-     */
     
+    // depreciated - use Pman.Download()
     
     download : function(c) {
         
-        if (c.newWindow) {
-            // as ie seems buggy...
-            window.open( c.url + '?' + Roo.urlEncode(c.params || {}), '_blank');
-            return;
-            
-        }
-        
-        this.createCsvFrame();
-        function cb(){
-            var r = { responseText : "", responseXML : null };
-
-            var frame = this.csvFrame;
-
-            try { 
-                var doc = Ext.isIE ? 
-                    frame.contentWindow.document : 
-                    (frame.contentDocument || window.frames[this.csvFrame.id].document);
-                
-                if(doc && doc.body && doc.body.innerHTML.length){
-                  //  alert(doc.body.innerHTML);
-                    Ext.MessageBox.alert("Error download",doc.body.innerHTML);
-                }
-                 
-            }
-            catch(e) {
-            }
-
-            Ext.EventManager.removeListener(frame, 'load', cb, this);
-        }
-        Ext.EventManager.on( this.csvFrame, 'load', cb, this);
-        this.csvFrame.src = c.url;
+        return new Pman.Download(c);
     },
+    
+    // fixme - move to document manager...
     downloadRevision : function(doc, rev)
     {
         this.download({
@@ -681,18 +640,20 @@ Pman = new Roo.Document(
         }); 
                     
     },
+    
+    
     exportCSV : function(c) {
-        //this.createCsvFrame(); 
+        
         for(var i=0;i < c.csvFormat.length;i++) {
             c.params['csvCols['+i+']'] = c.csvFormat[i][0];
             c.params['csvTitles['+i+']'] = c.csvFormat[i][1];
         }
-        
-        
-        c.url +=  '?' + Ext.urlEncode(c.params);
+        c.url +=  '?' + Roo.urlEncode(c.params);
         this.download(c);
 
     },
+    
+    
     prettyDate : function (value) 
     {
         if (typeof(value) == 'string') {
@@ -795,7 +756,7 @@ Pman = new Roo.Document(
     register : function(obj) {
         if (!obj.parent) {
             if (obj.parent === false) {
-                console.log('skip module (no parent)' + o.modkey);
+                //console.log('skip module (no parent)' + obj.modkey);
                 return;
             }
             
@@ -849,8 +810,8 @@ Pman = new Roo.Document(
             return;
         }
         // flash it up as modal - so we store the mask!?
-        Ext.MessageBox.show({ title: 'loading' });
-        Ext.MessageBox.show({
+        Roo.MessageBox.show({ title: 'loading' });
+        Roo.MessageBox.show({
            title: "Please wait...",
            msg: "Building Interface...",
            width:450,
@@ -862,25 +823,31 @@ Pman = new Roo.Document(
         var n = 0;
         var progressRun = function() {
             
-            var m = mods[n];
+            var mod = mods[n];
             
             
-            Ext.MessageBox.updateProgress(
+            Roo.MessageBox.updateProgress(
                 (n+1)/mods.length,  "Building Interface " + (n+1) + 
                     " of " + mods.length + 
-                    (m.name ? (' - ' + m.name) : '')
+                    (mod.name ? (' - ' + mod.name) : '')
                     );
             
             
             
-            if (typeof(m) == 'function') {
-                m();
+            if (typeof(mod) == 'function') {
+                mod();
                 
-            } else {
-                if (m.parent.layout && !m.module.disabled) {
-                    m.module.add(m.parent.layout, m.region);    
+            } else  if (mod.parent.layout && !mod.module.disabled) {
+                // honour permname setings..
+                if (mod.permname && mod.permname.length) {
+                    if (Pman.hasPerm(mod.permname, 'S')) {
+                        mod.module.add(mod.parent.layout, mod.region);    
+                    }
+                } else {
+                    mod.module.add(mod.parent.layout, mod.region);    
                 }
-                
+                    
+                 
             }
             
             
@@ -899,38 +866,6 @@ Pman = new Roo.Document(
         
     },
     
-    gtranslate : function(str, src, dest, cb) {
-        // load script: 
-        
-        
-        var x = new Roo.data.ScriptTagProxy({ 
-            url:  'http://ajax.googleapis.com/ajax/services/language/translate', 
-            callbackParam : 'callback' 
-        });
-        x.load(
-            {
-                v: '1.0',
-                q : str,
-                langpair : src + '|' +dest
-            }, // end params.
-            { // reader
-                readRecords : function (o) {
-                    if (!o.responseData) {
-                        return o;
-                    }
-                    return o.responseData.translatedText;
-                }
-            }, 
-            function (result) {
-                cb(result);
-            },
-            this,
-            []
-        );
-        
-            
-        
-    } ,
     invertColor : function(c)
     {
         // read..