sync
[web.mtrack] / MTrackWeb / templates / images / js / mtrack2.js
index 253fa19..cfcfe61 100644 (file)
  * 
  */
 
-
 MTrack = {
-    
+    init : function()
+    {
+        
+        Roo.onReady(function () {
+            //MTrack.footerSetAndWait();
+            if (authUser) {
+                window.setTimeout(MTrack.keepLoggedIn, 30000);
+                
+            }
+            
+            
+            
+        });
+            
+        Roo.onReady( function () {
+            var path = [ 'Tree' ];
+            //if (repoName) path.push( repoName );
+            // ??/ jump?
+            
+            var href = (window.location.pathname + window.location.search).substring(baseURL.length);
+            try { 
+                window.history.pushState( { url: href }, document.title , window.location.pathname + window.location.search );
+            } catch (e) {}
+            MTrack.currentURL = href;
+            Roo.Ajax.request( {
+                method: 'GET',
+                url : window.location.pathname + window.location.search,
+                params: { ajax_body : 1 } ,
+                success : function (data) {
+                    var ab = Roo.get('ajaxbody');
+                    ab.dom.innerHTML = data.responseText;
+                    MTrack.addHandlers(ab);
+                    MTrack.missingHashes(ab, href)
+                }
+            }); 
+        });
+        
+    },
     registry : [],
     /**
      * usage:
@@ -31,14 +66,23 @@ MTrack = {
         });
     },
     
+    
     addHandlers : function (toWhat) 
     {
         // forEach? - no IE support?
         toWhat = toWhat || document.body; // 
         // run the main registry
-        MTrack.registry.forEach(function(cfg) {
-            var el = Roo.get(toWhat).select(cfg.selector,true)
-            el[cfg.method].apply(el, cfg.event ? [ event, args ] : [ args ] );  
+        Roo.each(MTrack.registry, function(cfg) {
+            //Roo.log("Add select:" + cfg.selector);
+            try { 
+                var el = Roo.get(toWhat).select(cfg.selector,true)
+                el[cfg.method].apply(el, cfg.event ? [ cfg.event, cfg.args ] : [ cfg.args ] );
+            } catch(e) {
+                Roo.log("Error applying select:" + cfg.selector);
+                Roo.log(e);
+                // do not throw any more..
+                
+            }
         });
         // any other weird crap goes here.
         
@@ -70,6 +114,7 @@ MTrack = {
     
     ajaxLoad : function(url,slideleft)
     { 
+        Roo.get(document.body).scrollTo('top',0,true);
         this.currentURL = url;
         var target = Roo.get("ajaxbody");
         var content = Roo.get("content");
@@ -78,8 +123,8 @@ MTrack = {
         Roo.select('.mask').show(); // must show first?
         Roo.select('.mask-loading').show();
         // content has a border...
-        var t = content.getBox().top - Roo.get(document).getScroll().top - 13;
-        var l = content.getBox().left - Roo.get(document).getScroll().top - 13;
+        var t = content.getBox().y  ;// - Roo.get(document).getScroll().top;// - 13;
+        var l = content.getBox().x  ;// - Roo.get(document).getScroll().left;// - 13;
         var w = content.getBox().width+ 26;
         var h = content.getBox().height + 26;
      
@@ -90,35 +135,40 @@ MTrack = {
                 l + ( w / 2) - 16, t +   16 
         );
         
-        if (MTrack.missingHashRequest) {
-            MTrack.missingHashRequest.abort();
-            MTrack.missingHashRequest = false;
-        }
+        //if (MTrack.missingHashRequest) {
+            Roo.Ajax.abort();
+        //    MTrack.missingHashRequest = false;
+        //}
         Roo.get('loader').hide();
+        Roo.get('loader').setStyle('position', 'relative');
         Roo.Ajax.request({
+            method: 'GET',
             url : baseURL + url,
             params : { ajax_body : 1 },
             success : function(data) {
                 
                 Roo.select('.mask').hide();
-                Roo.get('loader').update(data);
+                Roo.get('loader').update(data.responseText);
                 Roo.get('loader').show();
                 Roo.get('loader').setWidth( w );
-                Roo.get('loader').setPosition( slideleft?  l+w : l-w , t  );
+                Roo.get('loader').setLocation( slideleft?  l+w : l-w , t  );
                 
+                // old layer - move it away..
                 target.animate(
                     {
-                        left: slideleft ? -1 * w  : w
+                        left: { from :  0  , to : slideleft ? -1 * w  : w }
                     },
                     .5,
                     function() {
-                        target.setPosition(  0, 0 ); // reset it at end of animation - as it ends up with the new content.
-                    }
+                        // reset it at end of animation - as it ends up with the new content.
+                        //target.setLocation(  0 , t ); 
+                    },
+                    'easeOut', 'motion'
                 );
                 
                 Roo.get('loader').animate(
                     {
-                            left: l+13
+                            left: { from : slideleft?  l+w : l-w , to : l  }
                     },
                     .5,
                     function () {
@@ -126,10 +176,14 @@ MTrack = {
                         Roo.get('loader').hide();
                         Roo.get('loader').update("");
                         target.show();// make sure!!
-                    
+                        target.setLocation( l ,t  );
+                        
                         MTrack.missingHashes(target,  url);
                         MTrack.addHandlers(target);
-                    }
+                        // scroll up...
+                        
+                    },
+                     'easeOut', 'motion'
                 );
             }
             //console.log('loaded dif');
@@ -143,22 +197,24 @@ MTrack = {
     
     missingHashRequest : false,
     missingHashes: function(el,url) {
-        //console.log('finding missing hashes?');
+        console.log('finding missing hashes?');
         var hashes = [];
         el.select('.browse-missing-hash').each(function() {
             hashes.push(this.dom.id);
         });
+        
         if (!hashes.length) {
+            Roo.log("no missing hashes");
             return;
         }
-        if (MTrack.missingHashRequest) {
-            MTrack.missingHashRequest.abort();
-        }
-        MTrack.missingHashRequest = Roo.Ajax.request({
+        Roo.Ajax.abort();
+        Roo.Ajax.request({
             method : 'POST',
             url : baseURL + url,
             params : { hashes : hashes.join(',') },
-            success : function(data) {
+            success : function(res) {
+                var data = Roo.decode(res.responseText);
+                
                 //console.log(data.data);
                 if (data.data) {
                     for(var hash in data.data) {
@@ -175,8 +231,86 @@ MTrack = {
             }
         });
         
-    }
+    },
+    last_dh : false,
+    last_wh : false,
+   
+    footerPosition : function (force) {
+        return;
+        var ele = Roo.get('footer');
+        if (!force &&
+            (MTrack.last_dh != Roo.lib.Dom.getDocumentHeight() || MTrack.last_wh != Roo.lib.Dom.getViewHeight())) {
+          force = true;
+        }
         
+        if (force) {
+          // Force a from-scratch layout assessment; put the footer back in
+          // it's natural location in the doc
+          ele.setStyle({
+            position: "relative",
+            "margin-top": "3em",
+            top: 0
+          });
+        }
+        if (Roo.lib.Dom.getDocumentHeight() <= Roo.lib.Dom.getViewHeight()) {
+          ele.setStyle({
+            position: "absolute",
+            "margin-top": "0",
+            top: (
+                Roo.get(document).getScroll().top +
+                Roo.lib.Dom.getViewHeight() -
+                ele.getSize().height - 1
+              )+"px"
+          });
+        } else {
+          ele.setStyle({
+            position: "relative",
+            "margin-top": "3em"
+          });
+        }
+        MTrack.last_dh =  Roo.lib.Dom.getDocumentHeight();
+        MTrack.last_wh = Roo.lib.Dom.getViewHeight();
+    },
+    
+    
+    keepLoggedIn: function()
+    {
+        Roo.Ajax.request({
+            url : baseURL + '/Login.html',
+            method:  'POST',
+            data : { refresh : 1 },
+            success : function() {
+                
+                window.setTimeout(MTrack.keepLoggedIn, 30000);
+                // what if it's false..currentURL = false;
+                
+                
+            }
+            
+        })
+        
+        
+        
+    },
+      /*
+      
+       $(window)
+        .scroll(mtrack_footer_position)
+        .resize(mtrack_footer_position);
+        
+      */
+        
+    footerSetAndWait : function () {
+        return;
+        /*this.footerPosition();
+        window.setTimeout(function () {
+          MTrack.footerSetAndWait();
+        }, 1500);
+        */
+    }
+    
+    
+    
         
 }
 
@@ -187,7 +321,8 @@ Roo.onReady(function() {
     Roo.select('#banner select').on('change', function(e) {
         // ajax change project, and refresh body..
         Roo.Ajax.request({
-            url : baseURL + '/Project.html',
+            method: 'GET',
+            url : baseURL + '/core_project',
             params : { active_project_id : this.value },
             success : function() {
                 // what if it's false..currentURL = false;
@@ -201,7 +336,7 @@ Roo.onReady(function() {
         
         
 });
-
+ MTrack.init();
 
 try { 
     window.onpopstate = function(ev) {
@@ -235,11 +370,15 @@ MTrack.register('a.browse-link', 'on', 'click', function(event)
 {
     event.preventDefault();
   
-    var href= this.getAttribute('href').substring(baseURL.length);
+    var href= this.dom.getAttribute('href').substring(baseURL.length);
     try { 
-        window.history.pushState( { url: href }, "Browse : " + href , this.href );
-    } catch (e) {}
-    var slideleft = $(this).is('.browse-link-up')  ? 0 : 1;    
+        window.history.pushState( { url: href }, "Browse : " + href , this.dom.href );
+        Roo.log("history push state");
+    } catch (e) {
+        Roo.log(e);
+        
+    }
+    var slideleft = this.is('.browse-link-up')  ? 0 : 1;    
     MTrack.ajaxLoad(href,slideleft); 
 });
 
@@ -292,7 +431,7 @@ $(document).ready(function() {
       {separator:'---------------' },
       {name:'Quotes', openWith:'(!(> |!|>)!)'},
       {name:'Code', openWith:'{{{\\n', closeWith:'\\n}}}'},
-      {separator:'---------------' },
+      {separator:'---------------' },1
       {name:'Preview', call:'preview', className:'preview'}
     ]
   });
@@ -396,55 +535,7 @@ $(document).ready(function() {
   $('input[title!=""]').mtrackWatermark();
  
 
-  // Arrange for the footer to sink to the bottom of the window, if the window
-  // contents are not very tall
-  var last_dh = 0;
-  var last_wh = 0;
-  function mtrack_footer_position(force) {
-    var ele = $('#footer');
-    if (!force &&
-        (last_dh != $(document).height() || last_wh != $(window).height)) {
-      force = true;
-    }
-    if (force) {
-      // Force a from-scratch layout assessment; put the footer back in
-      // it's natural location in the doc
-      ele.css({
-        position: "relative",
-        "margin-top": "3em",
-        top: 0
-      });
-    }
-    if ($(document).height() <= $(window).height()) {
-      ele.css({
-        position: "absolute",
-        "margin-top": "0",
-        top: (
-            $(window).scrollTop() +
-            $(window).height() -
-            ele.height() - 1
-          )+"px"
-      });
-    } else {
-      ele.css({
-        position: "relative",
-        "margin-top": "3em"
-      });
-    }
-    last_dh = $(document).height();
-    last_wh = $(window).height();
-  }
-  window.mtrack_footer_position = mtrack_footer_position;
-  $(window)
-    .scroll(mtrack_footer_position)
-    .resize(mtrack_footer_position);
-  function mtrack_footer_set_and_wait() {
-    mtrack_footer_position();
-    setTimeout(function () {
-      mtrack_footer_set_and_wait();
-    }, 1500);
-  }
-  mtrack_footer_set_and_wait();
+   
 });