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             window.mtrack_footer_position();
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                     
47                     $('#ajaxbody').html(data);
48                     MTrack.addHandlers($('#ajaxbody'));
49                     MTrack.missingHashes($('#ajaxbody'), 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().top - Roo.get(document).getScroll().top - 13;
120         var l = content.getBox().left - Roo.get(document).getScroll().top - 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             MTrack.missingHashRequest.abort();
133             MTrack.missingHashRequest = false;
134         }
135         Roo.get('loader').hide();
136         Roo.Ajax.request({
137             url : baseURL + url,
138             params : { ajax_body : 1 },
139             success : function(data) {
140                 
141                 Roo.select('.mask').hide();
142                 Roo.get('loader').update(data);
143                 Roo.get('loader').show();
144                 Roo.get('loader').setWidth( w );
145                 Roo.get('loader').setPosition( slideleft?  l+w : l-w , t  );
146                 
147                 target.animate(
148                     {
149                         left: slideleft ? -1 * w  : w
150                     },
151                     .5,
152                     function() {
153                         target.setPosition(  0, 0 ); // reset it at end of animation - as it ends up with the new content.
154                     }
155                 );
156                 
157                 Roo.get('loader').animate(
158                     {
159                             left: l+13
160                     },
161                     .5,
162                     function () {
163                         target.update( Roo.get('loader').dom.innerHTML);
164                         Roo.get('loader').hide();
165                         Roo.get('loader').update("");
166                         target.show();// make sure!!
167                     
168                         MTrack.missingHashes(target,  url);
169                         MTrack.addHandlers(target);
170                     }
171                 );
172             }
173             //console.log('loaded dif');
174             
175                
176         });
177       
178         return false;  
179     },
180     
181     
182     missingHashRequest : false,
183     missingHashes: function(el,url) {
184         //console.log('finding missing hashes?');
185         var hashes = [];
186         el.select('.browse-missing-hash').each(function() {
187             hashes.push(this.dom.id);
188         });
189         if (!hashes.length) {
190             return;
191         }
192         if (MTrack.missingHashRequest) {
193             MTrack.missingHashRequest.abort();
194         }
195         MTrack.missingHashRequest = Roo.Ajax.request({
196             method : 'POST',
197             url : baseURL + url,
198             params : { hashes : hashes.join(',') },
199             success : function(data) {
200                 //console.log(data.data);
201                 if (data.data) {
202                     for(var hash in data.data) {
203                         var o = data.data[hash];
204                         Roo.select('#'+ hash).first().dom.innerHTML =  o.changeby + ' : ' + o.changelog;
205                         Roo.select('#age-'+ hash).first().dom.innerHTML = o.age ; // do magic replacement!!!
206                         Roo.select('#rev-'+ hash).first().dom.innerHTML = o.rev ; // do magic replacement!!!
207                         MTrack.addHandlers(Roo.select('#age-'+ hash).first());
208                         MTrack.missingHashRequest  = false;
209                     }
210                     
211                 }
212                // console.log(data)
213             }
214         });
215         
216     }
217     
218     function footerPosition(force) {
219         var ele = Roo.get('footer');
220         if (!force &&
221             (last_dh != Roo.lib.Dom.getDocumentHeight() || last_wh != Roo.lib.Dom.getViewHeight())) {
222           force = true;
223         }
224         
225         if (force) {
226           // Force a from-scratch layout assessment; put the footer back in
227           // it's natural location in the doc
228           ele.setStyle({
229             position: "relative",
230             "margin-top": "3em",
231             top: 0
232           });
233         }
234         if (Roo.lib.Dom.getDocumentHeight() <= Roo.lib.Dom.getViewHeight()) {
235           ele.setStyle({
236             position: "absolute",
237             "margin-top": "0",
238             top: (
239                 Roo.get(window).getScroll().top +
240                  Roo.lib.Dom.getViewHeight() -
241                 ele.getSize().height - 1
242               )+"px"
243           });
244         } else {
245           ele.setStyle({
246             position: "relative",
247             "margin-top": "3em"
248           });
249         }
250         last_dh = $(document).height();
251         last_wh = $(window).height();
252       }
253       window.mtrack_footer_position = mtrack_footer_position;
254       $(window)
255         .scroll(mtrack_footer_position)
256         .resize(mtrack_footer_position);
257       function mtrack_footer_set_and_wait() {
258         mtrack_footer_position();
259         setTimeout(function () {
260           mtrack_footer_set_and_wait();
261         }, 1500);
262       }
263       mtrack_footer_set_and_wait();
264     });
265     
266     
267         
268 }
269
270 Roo.onReady(function() {
271     MTrack.addHandlers(); // adds to main body..
272     // change project.
273     
274     Roo.select('#banner select').on('change', function(e) {
275         // ajax change project, and refresh body..
276         Roo.Ajax.request({
277             url : baseURL + '/Project.html',
278             params : { active_project_id : this.value },
279             success : function() {
280                 // what if it's false..currentURL = false;
281                 MTrack.ajaxLoad(MTrack.currentURL, true);
282                 
283             }
284             
285         })
286          
287     });
288         
289         
290 });
291
292
293 try { 
294     window.onpopstate = function(ev) {
295          
296         if (!ev.state || typeof(ev.state.url) == 'undefined') {
297             return;
298         }
299         MTrack.ajaxLoad(ev.state.url, false);
300 };
301 } catch (e) {}
302     
303      
304      
305
306
307
308
309 // any date picers.. - on milestones?
310 MTrack.register('.dateinput', 'each', function(e) {
311     var ee = new Roo.form.DateField({
312         dateFormat: 'Y-m-d' // nice and compatible..
313     });
314     ee.applyTo(e);
315     // minDate: 0,
316     
317 } );
318
319
320
321 MTrack.register('a.browse-link', 'on', 'click', function(event) 
322 {
323     event.preventDefault();
324   
325     var href= this.getAttribute('href').substring(baseURL.length);
326     try { 
327         window.history.pushState( { url: href }, "Browse : " + href , this.href );
328     } catch (e) {}
329     var slideleft = $(this).is('.browse-link-up')  ? 0 : 1;    
330     MTrack.ajaxLoad(href,slideleft); 
331 });
332
333
334
335 //// ------------------- OLD STUFF NEEDS TIDY UP ----------------------
336
337 /*
338
339
340 $(document).ready(function() {
341     
342      
343     
344   
345   $("textarea.wiki").markItUp({
346     nameSpace:          "wiki",
347     previewParserPath:  baseURL + "/Preview",
348     root: rootURL + "/js",
349     onShiftEnter:       {keepDefault:false, replaceWith:'\\n\\n'},
350     markupSet:  [
351       {
352         name:'Heading 1', key:'1',
353         openWith:'== ', closeWith:' ==', placeHolder:'Your title here...'
354       },
355       {
356         name:'Heading 2', key:'2',
357         openWith:'=== ', closeWith:' ===', placeHolder:'Your title here...'
358       },
359       {
360         name:'Heading 3', key:'3',
361         openWith:'==== ', closeWith:' ====', placeHolder:'Your title here...'
362       },
363       {
364         name:'Heading 4', key:'4',
365         openWith:'===== ', closeWith:' =====', placeHolder:'Your title here...'
366       },
367       {
368         name:'Heading 5', key:'5',
369         openWith:'====== ', closeWith:' ======',
370         placeHolder:'Your title here...'
371       },
372       {separator:'---------------' },
373       {name:'Bold', key:'B', openWith:"'''", closeWith:"'''"},
374       {name:'Italic', key:'I', openWith:"''", closeWith:"''"},
375       {name:'Stroke through', key:'S', openWith:'~~', closeWith:'~~'},
376       {separator:'---------------' },
377       {name:'Bulleted list', openWith:' * '},
378       {name:'Numeric list', openWith:' 1. '},
379       {separator:'---------------' },
380       {name:'Quotes', openWith:'(!(> |!|>)!)'},
381       {name:'Code', openWith:'{{{\\n', closeWith:'\\n}}}'},
382       {separator:'---------------' },
383       {name:'Preview', call:'preview', className:'preview'}
384     ]
385   });
386
387   $.tablesorter.addParser({
388     id: 'ticket',
389     is: function(s) {
390       return /^#\d+/.test(s);
391     },
392     format: function(s) {
393       return $.tablesorter.formatFloat(s.replace(new RegExp(/#/g), ''));
394     },
395     type: 'numeric'
396   });
397  
398   $.tablesorter.addParser({
399     id: 'mtrackdate',
400     is: function(s) {
401       // don't auto-detect
402       return false;
403     },
404     format: function(s) {
405       // relies on the textExtraction routine below to pull a
406       // date/time string out of the title portion of the abbr tag
407       return $.tablesorter.formatFloat(new Date(s).getTime());
408     },
409     type: 'numeric'
410   });
411   
412   
413   
414   $("table.report, table.wiki").tablesorter({
415     textExtraction: function(node) {
416       var kid = node.childNodes[0];
417       if (kid && kid.tagName == 'ABBR') {
418         // assuming that this abbr is of class='timeinterval'
419         return kid.title;
420       }
421       // default 'simple' behavior
422       if (kid && kid.hasChildNodes()) {
423         return kid.innerHTML;
424       }
425       return node.innerHTML;
426     }
427   });
428   
429   
430   $('input.search[type=text]').each(function () {
431     if ($.browser.webkit) {
432       this.type = 'search';
433       ///$(this).attr('autosave', ABSWEB+'/');
434       $(this).attr('results', 5);
435     } else {
436       $(this).addClass('roundsearch');
437     }
438   });
439   // Convert links that are styled after buttons into actual buttons
440   $('a.button[href]').each(function () {
441     var href = $(this).attr('href');
442     var but = $('<button type="button"/>');
443     but.text($(this).text());
444     $(this).replaceWith(but);
445     but.click(function () {
446       document.location.href = href;
447       return false;
448     });
449   });
450
451   $.fn.mtrackWatermark = function () {
452     this.each(function () {
453       var ph = $(this).attr('title');
454       if ($.browser.webkit) {
455         // Use native safari placeholder for watermark
456         $(this).attr('placeholder', ph);
457       } else {
458         // http://plugins.jquery.com/files/jquery.tinywatermark-2.0.0.js.txt
459         var w;
460         var me = $(this);
461         me.focus(function () {
462           if (w) {
463             w = 0;
464             me.removeClass('watermark').data('w', 0).val('');
465           }
466         })
467         .blur(function () {
468           if (!me.val()) {
469             w = 1;
470             me.addClass('watermark').data('w', 1).val(ph);
471           }
472         })
473         .closest('form').submit(function () {
474           if (w) {
475             me.val('');
476           }
477         });
478         me.blur();
479       }
480     });
481   };
482   // Watermarking -??? what??
483   $('input[title!=""]').mtrackWatermark();
484  
485
486   // Arrange for the footer to sink to the bottom of the window, if the window
487   // contents are not very tall
488   var last_dh = 0;
489   var last_wh = 0;
490   function mtrack_footer_position(force) {
491     var ele = $('#footer');
492     if (!force &&
493         (last_dh != $(document).height() || last_wh != $(window).height)) {
494       force = true;
495     }
496     if (force) {
497       // Force a from-scratch layout assessment; put the footer back in
498       // it's natural location in the doc
499       ele.css({
500         position: "relative",
501         "margin-top": "3em",
502         top: 0
503       });
504     }
505     if ($(document).height() <= $(window).height()) {
506       ele.css({
507         position: "absolute",
508         "margin-top": "0",
509         top: (
510             $(window).scrollTop() +
511             $(window).height() -
512             ele.height() - 1
513           )+"px"
514       });
515     } else {
516       ele.css({
517         position: "relative",
518         "margin-top": "3em"
519       });
520     }
521     last_dh = $(document).height();
522     last_wh = $(window).height();
523   }
524   window.mtrack_footer_position = mtrack_footer_position;
525   $(window)
526     .scroll(mtrack_footer_position)
527     .resize(mtrack_footer_position);
528   function mtrack_footer_set_and_wait() {
529     mtrack_footer_position();
530     setTimeout(function () {
531       mtrack_footer_set_and_wait();
532     }, 1500);
533   }
534   mtrack_footer_set_and_wait();
535 });
536  
537
538 // from file.php
539
540
541 // from head -- probably for reports only..
542
543  
544 $(document).ready(function() {
545          
546       $.tablesorter.addParser({
547         id: 'priority',
548         is: function(s) {
549           // don't auto-detect
550           return false;
551         },
552         format: function(s) {
553             if (typeof(priorities[s]) != 'undefined') {
554                 return priorities[s];
555             }
556             return s;
557         },
558         type: 'numeric'
559       });
560       
561       $.tablesorter.addParser({
562         id: 'severity',
563         is: function(s) {
564           // don't auto-detect
565           return false;
566         },
567         format: function(s) {
568             if (typeof(severities[s]) != 'undefined') {
569                 return severities[s];
570             }
571             return s;
572         },
573         type: 'numeric'
574     });
575 });
576
577 // from wiki..
578
579 $(document).ready(function(){
580   $('ul.wikitree').treeview({
581     collapsed: true,
582     persist: "location"
583   });
584 });
585
586  */