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