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