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