MTrackWeb/templates/images/js/mtrack2.js
[web.mtrack] / MTrackWeb / templates / images / js / mtrack2.js
1 //<Script type="text/javascript">
2
3 /**
4  * Roo conversion....
5  * 
6  * currenlty mostly a clone of the JQuery version..
7  *
8  * uses a simple  registry - all code get's added to it, 
9  * then whenever html is loaded via AJAX, we can run run through the handlers and add them.
10  * 
11  */
12
13
14  
15 MTrack = {
16     init : function()
17     {
18         
19         Roo.onReady(function () {
20             MTrack.footerSetAndWait();
21             if (authUser) {
22                 setTimeout(MTrack.keepLoggedIn, 30000);
23                 
24             }
25             
26             
27             
28         });
29             
30         Roo.onReady( function () {
31             var path = [ 'Tree' ];
32             //if (repoName) path.push( repoName );
33             // ??/ jump?
34             
35             var href = (window.location.pathname + window.location.search).substring(baseURL.length);
36             try { 
37                 window.history.pushState( { url: href }, document.title , window.location.pathname + window.location.search );
38             } catch (e) {}
39             MTrack.currentURL = href;
40             Roo.Ajax.request( {
41                 method: 'GET',
42                 url : window.location.pathname + window.location.search,
43                 params: { ajax_body : 1 } ,
44                 success : function (data) {
45                     Roo.log(data);
46                     var ab = Roo.get('ajaxbody');
47                     ab.dom.innerHTML = data.responseText;
48                     MTrack.addHandlers(ab);
49                     MTrack.missingHashes(ab, href)
50                 }
51             }); 
52         });
53         
54     },
55     registry : [],
56     /**
57      * usage:
58      * MTrack.register('a.changeset-link', 'each', function() ....)
59      * MTrack.register('a.changeset-link', 'on', 'click', function() ....)
60      * 
61      */
62     register : function( selector, method, arg1, arg2) 
63     {
64         MTrack.registry.push( {
65             selector : selector,
66             method : method,
67             event : method == 'on' ? arg1 : false,
68             args : method == 'on' ? arg2 : arg1 
69         });
70     },
71     
72     addHandlers : function (toWhat) 
73     {
74         // forEach? - no IE support?
75         toWhat = toWhat || document.body; // 
76         // run the main registry
77         MTrack.registry.forEach(function(cfg) {
78             var el = Roo.get(toWhat).select(cfg.selector,true)
79             el[cfg.method].apply(el, cfg.event ? [ cfg.event, cfg.args ] : [ cfg.args ] );  
80         });
81         // any other weird crap goes here.
82         
83         if (Roo.isGecko) {
84             Roo.select(toWhat,true).select("form").set( { "autocomplete" : "off" });
85         }
86         // time ago 
87         //jQuery.timeago.settings.allowFuture = true;
88         //$(toWhat).find('abbr.timeinterval').timeago();
89         
90         // multipe select addon
91         //$(toWhat).find("select[multiple]").asmSelect({
92         //    addItemTarget: 'bottom',
93         //    animate: false,
94         //    highlight: false,
95         //    removeLabel: '[x]',
96         //    sortable: false
97         //});
98       
99     },
100     
101     currentURL : false,
102     missingHashRequest : false,
103     
104     
105     // This is the main body load tool...
106     // it still needs to handle anchors...
107     
108     
109     ajaxLoad : function(url,slideleft)
110     { 
111         this.currentURL = url;
112         var target = Roo.get("ajaxbody");
113         var content = Roo.get("content");
114         target.setStyle('position', 'relative');
115         
116         Roo.select('.mask').show(); // must show first?
117         Roo.select('.mask-loading').show();
118         // content has a border...
119         var t = content.getBox().y  ;// - Roo.get(document).getScroll().top;// - 13;
120         var l = content.getBox().x  ;// - Roo.get(document).getScroll().left;// - 13;
121         var w = content.getBox().width+ 26;
122         var h = content.getBox().height + 26;
123      
124         Roo.select('.mask').first().setLocation(l,t);
125         Roo.select('.mask').first().setSize( w , h, false  );
126         
127         Roo.select('.mask-loading').first().setLocation(
128                 l + ( w / 2) - 16, t +   16 
129         );
130         
131         //if (MTrack.missingHashRequest) {
132             Roo.Ajax.abort();
133         //    MTrack.missingHashRequest = false;
134         //}
135         Roo.get('loader').hide();
136         Roo.Ajax.request({
137             method: 'GET',
138             url : baseURL + url,
139             params : { ajax_body : 1 },
140             success : function(data) {
141                 
142                 Roo.select('.mask').hide();
143                 Roo.get('loader').update(data.responseText);
144                 Roo.get('loader').show();
145                 Roo.get('loader').setWidth( w );
146                 Roo.get('loader').setLocation( slideleft?  l+w : l-w , t  );
147                 
148                 // old layer - move it away..
149                 target.animate(
150                     {
151                         left: { from :  0  , to : slideleft ? -1 * w  : w }
152                     },
153                     .5,
154                     function() {
155                         // reset it at end of animation - as it ends up with the new content.
156                         //target.setLocation(  0 , t ); 
157                     },
158                     'easeOut', 'motion'
159                 );
160                 
161                 Roo.get('loader').animate(
162                     {
163                             left: { from : slideleft?  l+w : l-w , to : l  }
164                     },
165                     .5,
166                     function () {
167                         target.update( Roo.get('loader').dom.innerHTML);
168                         Roo.get('loader').hide();
169                         Roo.get('loader').update("");
170                         target.show();// make sure!!
171                         target.setLocation( l ,t  );
172                         
173                         MTrack.missingHashes(target,  url);
174                         MTrack.addHandlers(target);
175                     },
176                      'easeOut', 'motion'
177                 );
178             }
179             //console.log('loaded dif');
180             
181                
182         });
183       
184         return false;  
185     },
186     
187     
188     missingHashRequest : false,
189     missingHashes: function(el,url) {
190         //console.log('finding missing hashes?');
191         var hashes = [];
192         el.select('.browse-missing-hash').each(function() {
193             hashes.push(this.dom.id);
194         });
195         if (!hashes.length) {
196             return;
197         }
198         if (MTrack.missingHashRequest) {
199             MTrack.missingHashRequest.abort();
200         }
201         MTrack.missingHashRequest = Roo.Ajax.request({
202             method : 'POST',
203             url : baseURL + url,
204             params : { hashes : hashes.join(',') },
205             success : function(data) {
206                 //console.log(data.data);
207                 if (data.data) {
208                     for(var hash in data.data) {
209                         var o = data.data[hash];
210                         Roo.select('#'+ hash).first().dom.innerHTML =  o.changeby + ' : ' + o.changelog;
211                         Roo.select('#age-'+ hash).first().dom.innerHTML = o.age ; // do magic replacement!!!
212                         Roo.select('#rev-'+ hash).first().dom.innerHTML = o.rev ; // do magic replacement!!!
213                         MTrack.addHandlers(Roo.select('#age-'+ hash).first());
214                         MTrack.missingHashRequest  = false;
215                     }
216                     
217                 }
218                // console.log(data)
219             }
220         });
221         
222     },
223     last_dh : false,
224     last_wh : false,
225    
226     footerPosition : function (force) {
227         var ele = Roo.get('footer');
228         if (!force &&
229             (MTrack.last_dh != Roo.lib.Dom.getDocumentHeight() || MTrack.last_wh != Roo.lib.Dom.getViewHeight())) {
230           force = true;
231         }
232         
233         if (force) {
234           // Force a from-scratch layout assessment; put the footer back in
235           // it's natural location in the doc
236           ele.setStyle({
237             position: "relative",
238             "margin-top": "3em",
239             top: 0
240           });
241         }
242         if (Roo.lib.Dom.getDocumentHeight() <= Roo.lib.Dom.getViewHeight()) {
243           ele.setStyle({
244             position: "absolute",
245             "margin-top": "0",
246             top: (
247                 Roo.get(document).getScroll().top +
248                 Roo.lib.Dom.getViewHeight() -
249                 ele.getSize().height - 1
250               )+"px"
251           });
252         } else {
253           ele.setStyle({
254             position: "relative",
255             "margin-top": "3em"
256           });
257         }
258         MTrack.last_dh =  Roo.lib.Dom.getDocumentHeight();
259         MTrack.last_wh = Roo.lib.Dom.getViewHeight();
260     },
261     
262       /*
263       
264        $(window)
265         .scroll(mtrack_footer_position)
266         .resize(mtrack_footer_position);
267         
268       */
269         
270     footerSetAndWait : function () {
271         this.footerPosition();
272         setTimeout(function () {
273           MTrack.footerSetAndWait();
274         }, 1500);
275     }
276     
277     
278     
279         
280 }
281
282 Roo.onReady(function() {
283     MTrack.addHandlers(); // adds to main body..
284     // change project.
285     
286     Roo.select('#banner select').on('change', function(e) {
287         // ajax change project, and refresh body..
288         Roo.Ajax.request({
289             method: 'GET',
290             url : baseURL + '/Project.html',
291             params : { active_project_id : this.value },
292             success : function() {
293                 // what if it's false..currentURL = false;
294                 MTrack.ajaxLoad(MTrack.currentURL, true);
295                 
296             }
297             
298         })
299          
300     });
301         
302         
303 });
304
305
306 try { 
307     window.onpopstate = function(ev) {
308          
309         if (!ev.state || typeof(ev.state.url) == 'undefined') {
310             return;
311         }
312         MTrack.ajaxLoad(ev.state.url, false);
313 };
314 } catch (e) {}
315     
316      
317      
318
319
320
321
322 // any date picers.. - on milestones?
323 MTrack.register('.dateinput', 'each', function(e) {
324     var ee = new Roo.form.DateField({
325         dateFormat: 'Y-m-d' // nice and compatible..
326     });
327     ee.applyTo(e);
328     // minDate: 0,
329     
330 } );
331
332
333
334 MTrack.register('a.browse-link', 'on', 'click', function(event) 
335 {
336     event.preventDefault();
337   
338     var href= this.dom.getAttribute('href').substring(baseURL.length);
339     try { 
340         window.history.pushState( { url: href }, "Browse : " + href , this.href );
341     } catch (e) {}
342     var slideleft = this.is('.browse-link-up')  ? 0 : 1;    
343     MTrack.ajaxLoad(href,slideleft); 
344 });
345
346
347
348 //// ------------------- OLD STUFF NEEDS TIDY UP ----------------------
349
350 /*
351
352
353 $(document).ready(function() {
354     
355      
356     
357   
358   $("textarea.wiki").markItUp({
359     nameSpace:          "wiki",
360     previewParserPath:  baseURL + "/Preview",
361     root: rootURL + "/js",
362     onShiftEnter:       {keepDefault:false, replaceWith:'\\n\\n'},
363     markupSet:  [
364       {
365         name:'Heading 1', key:'1',
366         openWith:'== ', closeWith:' ==', placeHolder:'Your title here...'
367       },
368       {
369         name:'Heading 2', key:'2',
370         openWith:'=== ', closeWith:' ===', placeHolder:'Your title here...'
371       },
372       {
373         name:'Heading 3', key:'3',
374         openWith:'==== ', closeWith:' ====', placeHolder:'Your title here...'
375       },
376       {
377         name:'Heading 4', key:'4',
378         openWith:'===== ', closeWith:' =====', placeHolder:'Your title here...'
379       },
380       {
381         name:'Heading 5', key:'5',
382         openWith:'====== ', closeWith:' ======',
383         placeHolder:'Your title here...'
384       },
385       {separator:'---------------' },
386       {name:'Bold', key:'B', openWith:"'''", closeWith:"'''"},
387       {name:'Italic', key:'I', openWith:"''", closeWith:"''"},
388       {name:'Stroke through', key:'S', openWith:'~~', closeWith:'~~'},
389       {separator:'---------------' },
390       {name:'Bulleted list', openWith:' * '},
391       {name:'Numeric list', openWith:' 1. '},
392       {separator:'---------------' },
393       {name:'Quotes', openWith:'(!(> |!|>)!)'},
394       {name:'Code', openWith:'{{{\\n', closeWith:'\\n}}}'},
395       {separator:'---------------' },
396       {name:'Preview', call:'preview', className:'preview'}
397     ]
398   });
399
400   $.tablesorter.addParser({
401     id: 'ticket',
402     is: function(s) {
403       return /^#\d+/.test(s);
404     },
405     format: function(s) {
406       return $.tablesorter.formatFloat(s.replace(new RegExp(/#/g), ''));
407     },
408     type: 'numeric'
409   });
410  
411   $.tablesorter.addParser({
412     id: 'mtrackdate',
413     is: function(s) {
414       // don't auto-detect
415       return false;
416     },
417     format: function(s) {
418       // relies on the textExtraction routine below to pull a
419       // date/time string out of the title portion of the abbr tag
420       return $.tablesorter.formatFloat(new Date(s).getTime());
421     },
422     type: 'numeric'
423   });
424   
425   
426   
427   $("table.report, table.wiki").tablesorter({
428     textExtraction: function(node) {
429       var kid = node.childNodes[0];
430       if (kid && kid.tagName == 'ABBR') {
431         // assuming that this abbr is of class='timeinterval'
432         return kid.title;
433       }
434       // default 'simple' behavior
435       if (kid && kid.hasChildNodes()) {
436         return kid.innerHTML;
437       }
438       return node.innerHTML;
439     }
440   });
441   
442   
443   $('input.search[type=text]').each(function () {
444     if ($.browser.webkit) {
445       this.type = 'search';
446       ///$(this).attr('autosave', ABSWEB+'/');
447       $(this).attr('results', 5);
448     } else {
449       $(this).addClass('roundsearch');
450     }
451   });
452   // Convert links that are styled after buttons into actual buttons
453   $('a.button[href]').each(function () {
454     var href = $(this).attr('href');
455     var but = $('<button type="button"/>');
456     but.text($(this).text());
457     $(this).replaceWith(but);
458     but.click(function () {
459       document.location.href = href;
460       return false;
461     });
462   });
463
464   $.fn.mtrackWatermark = function () {
465     this.each(function () {
466       var ph = $(this).attr('title');
467       if ($.browser.webkit) {
468         // Use native safari placeholder for watermark
469         $(this).attr('placeholder', ph);
470       } else {
471         // http://plugins.jquery.com/files/jquery.tinywatermark-2.0.0.js.txt
472         var w;
473         var me = $(this);
474         me.focus(function () {
475           if (w) {
476             w = 0;
477             me.removeClass('watermark').data('w', 0).val('');
478           }
479         })
480         .blur(function () {
481           if (!me.val()) {
482             w = 1;
483             me.addClass('watermark').data('w', 1).val(ph);
484           }
485         })
486         .closest('form').submit(function () {
487           if (w) {
488             me.val('');
489           }
490         });
491         me.blur();
492       }
493     });
494   };
495   // Watermarking -??? what??
496   $('input[title!=""]').mtrackWatermark();
497  
498
499    
500 });
501  
502
503 // from file.php
504
505
506 // from head -- probably for reports only..
507
508  
509 $(document).ready(function() {
510          
511       $.tablesorter.addParser({
512         id: 'priority',
513         is: function(s) {
514           // don't auto-detect
515           return false;
516         },
517         format: function(s) {
518             if (typeof(priorities[s]) != 'undefined') {
519                 return priorities[s];
520             }
521             return s;
522         },
523         type: 'numeric'
524       });
525       
526       $.tablesorter.addParser({
527         id: 'severity',
528         is: function(s) {
529           // don't auto-detect
530           return false;
531         },
532         format: function(s) {
533             if (typeof(severities[s]) != 'undefined') {
534                 return severities[s];
535             }
536             return s;
537         },
538         type: 'numeric'
539     });
540 });
541
542 // from wiki..
543
544 $(document).ready(function(){
545   $('ul.wikitree').treeview({
546     collapsed: true,
547     persist: "location"
548   });
549 });
550
551  */