DataObjects/Core_event_audit.php
[Pman.Core] / Pman.js
diff --git a/Pman.js b/Pman.js
index 039d761..7d9552c 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(
@@ -21,6 +27,13 @@ Pman = new Roo.Document(
     subMenuItems : [],
     topMenuItems : [],
     rightNames: { }, /// register right names here - so they can be translated and rendered.
+    /**
+     * @property {Roo.menu.Menu} pulldownMenu - the 'add menu pulldown, you can use it to add items..
+     *
+     */
+    pulldownMenu : false, 
+    
+    
     buildCompleted : false, // flag to say if we are building interface..
     events : {
         'beforeload' : true, // fired after page ready, before module building.
@@ -37,16 +50,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 +110,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 +131,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 +140,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 +156,15 @@ Pman = new Roo.Document(
                 //resizeTabs: true,
                 alwaysShowTabs: true,
                 minTabWidth: 140
-            } /*,
+            } ,
             south: {
+                collapsible : true,
+                collapsed : true,
                 split:false,
-                initialSize: 25,
-                titlebar: false
+                height: 120,
+                titlebar: false 
             }
-            */
+            
         });
         
         this.fireEvent('beforeload',this);
@@ -157,20 +172,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 +193,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;
@@ -197,6 +212,12 @@ Pman = new Roo.Document(
                 _this.addTopToolbar();  
                 _this.finalize();
                 _this.fireEvent('load',this);
+                
+                if (!_this.layout.getRegion('south').panels.length) {
+                    _this.layout.getRegion('south').hide();
+                }
+                
+                
             }
         );
         
@@ -216,14 +237,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",
@@ -255,17 +276,19 @@ Pman = new Roo.Document(
             // since we always add it.. just chop of last item
             this.subMenuItems.pop(); 
             
-            lotb.add(
+            var btn = new Roo.Toolbar.Button( 
                 {
-                     
                     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
                     }     
-                } ,'-'
+                }
             );
+            this.pulldownMenu = btn.menu;
+            lotb.add(btn, '-');
+            
         }
        
         lotb.add(
@@ -289,7 +312,7 @@ Pman = new Roo.Document(
       
        
         window.onbeforeunload = function(e) { 
-            var e = e || window.event;
+            e = e || window.event;
             var r = "Closing this window will loose changes, are you sure you want to do that?";
 
             // For IE and Firefox
@@ -302,9 +325,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 +344,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 +356,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 +372,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..
             
@@ -364,7 +395,7 @@ Pman = new Roo.Document(
     },
     
     
-    
+    // REMOVE THESE 
     
      
     onLoadTrack : function(id,cb) {
@@ -379,7 +410,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 +419,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 +427,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);
                 //}
@@ -413,17 +444,39 @@ Pman = new Roo.Document(
           
     },
     
+    refreshActivePanel : function() {
+        var actpan = this.layout.getRegion('center').getActivePanel();
+        if (actpan.controller && actpan.controller.paging) {
+            actpan.controller.paging.onClick('refresh');
+            return;
+        }
+        
+        var agid = Pman.layout.getRegion('center').getActivePanel().id;
+        if (!agid) {
+            return;
+        }
+        Pman.Tab[agid].paging.onClick('refresh');
+    },
+    toCidV : function(data) {
+        return 'C' + data.in_out.substring(0,1) + data.cid;
+    },
+    
+    
     /**
      * eg. has Pman.hasPerm('Admin.Admin_Tab', 'S') == showlist..
      * 
      */
     hasPerm: function(name, lvl) {
-        if (typeof(Pman.Login.authUser) != 'object') {
-            return false;
-        }
-        if (typeof(Pman.Login.authUser.perms[name]) != 'string') {
-            return false;
+        if (
+            (typeof(Pman.Login.authUser) != 'object')
+            ||
+            (typeof(Pman.Login.authUser.perms) != 'object')
+            ||
+            (typeof(Pman.Login.authUser.perms[name]) != 'string')
+            ) {
+                return false;
         }
+        
         return Pman.Login.authUser.perms[name].indexOf(lvl) > -1;
         
     },
@@ -445,7 +498,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 +519,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 +527,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,67 +558,49 @@ Pman = new Roo.Document(
                     },
                     failure: function(act) {
                         tab.grid.getView().mainWrap.unmask();
-                        Ext.MessageBox.alert("Error", "Error Deleting");
+                        Roo.MessageBox.alert("Error", "Error Deleting");
                     }
                     
                 });
             }
+            
         );
+        return '';
     },
-    refreshActivePanel : function() {
-        var actpan = this.layout.getRegion('center').getActivePanel();
-        if (actpan.controller && actpan.controller.paging) {
-            actpan.controller.paging.onClick('refresh');
-            return;
-        }
-        
-        var agid = Pman.layout.getRegion('center').getActivePanel().id;
-        if (!agid) {
-            return;
-        }
-        Pman.Tab[agid].paging.onClick('refresh');
-    },
-    toCidV : function(data) {
-        return 'C' + data.in_out.substring(0,1) + data.cid;
-    },
+    
     
     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...
-     * c.url
-     * c.method
-     * c.params
-     * c.failure() == failure function..
-     * c.success(data) == success function..
-     * 
+     * Depreciated - USE new Pman.Request
+    * 
      * 
      */
     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 +616,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 +633,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 +658,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') {
@@ -772,7 +751,7 @@ Pman = new Roo.Document(
             }
             s = !s;
             document.title = s ? msg : oldtitle;
-                  
+            return false;     
         }, 1000); // every 120 secs = 2mins..
          document.title =   msg;
         
@@ -787,23 +766,39 @@ Pman = new Roo.Document(
      * Pman.register({
           modKey : '00-admin-xxxx',
           module : Pman.Tab.projectMgr,
+          moduleName : 'Pman.Tab.projectMgr',
           region : 'center',
           parent : Pman.layout
         })
      * 
      */
-    register : function(obj) {
+    register : function(obj)
+    {
+        
+        // ignore registration of objects which are disabled.
+        appDisabled = typeof(appDisabled) == 'undefined' ? [] : appDisabled;
+        
+        if ((typeof(obj.moduleName) != 'undefined')
+                && appDisabled.indexOf(obj.moduleName) > -1)
+        {
+            return;
+        }
+        
         if (!obj.parent) {
             if (obj.parent === false) {
-                //console.log(obj);
+                //console.log('skip module (no parent)' + obj.modkey);
                 return;
             }
-            
+            // this is an error condition - the parent does not exist..
+            // technically it should not happen..
+            console.log("Parent is missing");
             console.log(obj);
+            return;
         }
         if (!obj.parent.modules) {
             obj.parent.modules = new Roo.util.MixedCollection(false, function(o) { return o.modKey });
         }
+        
         obj.parent.modules.add(obj);
         
     },
@@ -848,8 +843,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,
@@ -861,25 +856,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);    
                 }
-                
+                    
+                 
             }
             
             
@@ -898,38 +899,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..