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