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