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