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 MTrack = {
15     
16     registry : [],
17     /**
18      * usage:
19      * MTrack.register('a.changeset-link', 'click', function() ....)
20      * 
21      */
22     register : function( selector, event, arg1, arg2) 
23     {
24         MTrack.registry.push( {
25             selector : selector,
26             method : method,
27             event : method == 'on' ? arg1 : false,
28             args : method == 'on' ? arg2 : arg1 
29         });
30     },
31     
32     addHandlers : function (toWhat) 
33     {
34         // forEach? - no IE support?
35         toWhat = toWhat || document.body; // 
36         // run the main registry
37         MTrack.registry.forEach(function(cfg) {
38             var el = Roo.get(toWhat).select(cfg.selector,true)
39             el[cfg.method].apply(el, cfg.event ? [ event, args ] : [ args ] );  
40         });
41         // any other weird crap goes here.
42         
43         if (Roo.isGecko) {
44             Roo.select(toWhat,true).select("form").set( { "autocomplete" : "off" });
45         }
46         // time ago 
47         //jQuery.timeago.settings.allowFuture = true;
48         //$(toWhat).find('abbr.timeinterval').timeago();
49         
50         // multipe select addon
51         //$(toWhat).find("select[multiple]").asmSelect({
52         //    addItemTarget: 'bottom',
53         //    animate: false,
54         //    highlight: false,
55         //    removeLabel: '[x]',
56         //    sortable: false
57         //});
58       
59     }
60     
61 }
62
63 Roo.onReady(function() {
64     MTrack.addHandlers(); // adds to main body..
65     // change project.
66     
67     Roo.select('#banner select').on('change', function(e) {
68         // ajax change project, and refresh body..
69         Roo.Ajax.request({
70             url : baseURL + '/Project.html',
71             params : { active_project_id : this.value },
72             success : function() {
73                 // what if it's false..currentURL = false;
74                 MTrack.ajaxLoad(MTrack.currentURL, true);
75                 
76             }
77             
78         })
79          
80     });
81         
82         
83 });
84
85 // any date picers.. - on milestones?
86 MTrack.register('.dateinput', 'each', function(e) {
87     var ee = new Roo.form.DateField({
88         dateFormat: 'yy-mm-dd' // nice and compatible..
89     });
90     ee.applyTo(e);
91     // minDate: 0,
92     
93 } );
94
95
96 //// ------------------- OLD STUFF NEEDS TIDY UP ----------------------
97
98
99
100
101 $(document).ready(function() {
102     
103      
104     
105   
106   $("textarea.wiki").markItUp({
107     nameSpace:          "wiki",
108     previewParserPath:  baseURL + "/Preview",
109     root: rootURL + "/js",
110     onShiftEnter:       {keepDefault:false, replaceWith:'\\n\\n'},
111     markupSet:  [
112       {
113         name:'Heading 1', key:'1',
114         openWith:'== ', closeWith:' ==', placeHolder:'Your title here...'
115       },
116       {
117         name:'Heading 2', key:'2',
118         openWith:'=== ', closeWith:' ===', placeHolder:'Your title here...'
119       },
120       {
121         name:'Heading 3', key:'3',
122         openWith:'==== ', closeWith:' ====', placeHolder:'Your title here...'
123       },
124       {
125         name:'Heading 4', key:'4',
126         openWith:'===== ', closeWith:' =====', placeHolder:'Your title here...'
127       },
128       {
129         name:'Heading 5', key:'5',
130         openWith:'====== ', closeWith:' ======',
131         placeHolder:'Your title here...'
132       },
133       {separator:'---------------' },
134       {name:'Bold', key:'B', openWith:"'''", closeWith:"'''"},
135       {name:'Italic', key:'I', openWith:"''", closeWith:"''"},
136       {name:'Stroke through', key:'S', openWith:'~~', closeWith:'~~'},
137       {separator:'---------------' },
138       {name:'Bulleted list', openWith:' * '},
139       {name:'Numeric list', openWith:' 1. '},
140       {separator:'---------------' },
141       {name:'Quotes', openWith:'(!(> |!|>)!)'},
142       {name:'Code', openWith:'{{{\\n', closeWith:'\\n}}}'},
143       {separator:'---------------' },
144       {name:'Preview', call:'preview', className:'preview'}
145     ]
146   });
147
148   $.tablesorter.addParser({
149     id: 'ticket',
150     is: function(s) {
151       return /^#\d+/.test(s);
152     },
153     format: function(s) {
154       return $.tablesorter.formatFloat(s.replace(new RegExp(/#/g), ''));
155     },
156     type: 'numeric'
157   });
158  
159   $.tablesorter.addParser({
160     id: 'mtrackdate',
161     is: function(s) {
162       // don't auto-detect
163       return false;
164     },
165     format: function(s) {
166       // relies on the textExtraction routine below to pull a
167       // date/time string out of the title portion of the abbr tag
168       return $.tablesorter.formatFloat(new Date(s).getTime());
169     },
170     type: 'numeric'
171   });
172   
173   
174   
175   $("table.report, table.wiki").tablesorter({
176     textExtraction: function(node) {
177       var kid = node.childNodes[0];
178       if (kid && kid.tagName == 'ABBR') {
179         // assuming that this abbr is of class='timeinterval'
180         return kid.title;
181       }
182       // default 'simple' behavior
183       if (kid && kid.hasChildNodes()) {
184         return kid.innerHTML;
185       }
186       return node.innerHTML;
187     }
188   });
189   
190   
191   $('input.search[type=text]').each(function () {
192     if ($.browser.webkit) {
193       this.type = 'search';
194       ///$(this).attr('autosave', ABSWEB+'/');
195       $(this).attr('results', 5);
196     } else {
197       $(this).addClass('roundsearch');
198     }
199   });
200   // Convert links that are styled after buttons into actual buttons
201   $('a.button[href]').each(function () {
202     var href = $(this).attr('href');
203     var but = $('<button type="button"/>');
204     but.text($(this).text());
205     $(this).replaceWith(but);
206     but.click(function () {
207       document.location.href = href;
208       return false;
209     });
210   });
211
212   $.fn.mtrackWatermark = function () {
213     this.each(function () {
214       var ph = $(this).attr('title');
215       if ($.browser.webkit) {
216         // Use native safari placeholder for watermark
217         $(this).attr('placeholder', ph);
218       } else {
219         // http://plugins.jquery.com/files/jquery.tinywatermark-2.0.0.js.txt
220         var w;
221         var me = $(this);
222         me.focus(function () {
223           if (w) {
224             w = 0;
225             me.removeClass('watermark').data('w', 0).val('');
226           }
227         })
228         .blur(function () {
229           if (!me.val()) {
230             w = 1;
231             me.addClass('watermark').data('w', 1).val(ph);
232           }
233         })
234         .closest('form').submit(function () {
235           if (w) {
236             me.val('');
237           }
238         });
239         me.blur();
240       }
241     });
242   };
243   // Watermarking -??? what??
244   $('input[title!=""]').mtrackWatermark();
245  
246
247   // Arrange for the footer to sink to the bottom of the window, if the window
248   // contents are not very tall
249   var last_dh = 0;
250   var last_wh = 0;
251   function mtrack_footer_position(force) {
252     var ele = $('#footer');
253     if (!force &&
254         (last_dh != $(document).height() || last_wh != $(window).height)) {
255       force = true;
256     }
257     if (force) {
258       // Force a from-scratch layout assessment; put the footer back in
259       // it's natural location in the doc
260       ele.css({
261         position: "relative",
262         "margin-top": "3em",
263         top: 0
264       });
265     }
266     if ($(document).height() <= $(window).height()) {
267       ele.css({
268         position: "absolute",
269         "margin-top": "0",
270         top: (
271             $(window).scrollTop() +
272             $(window).height() -
273             ele.height() - 1
274           )+"px"
275       });
276     } else {
277       ele.css({
278         position: "relative",
279         "margin-top": "3em"
280       });
281     }
282     last_dh = $(document).height();
283     last_wh = $(window).height();
284   }
285   window.mtrack_footer_position = mtrack_footer_position;
286   $(window)
287     .scroll(mtrack_footer_position)
288     .resize(mtrack_footer_position);
289   function mtrack_footer_set_and_wait() {
290     mtrack_footer_position();
291     setTimeout(function () {
292       mtrack_footer_set_and_wait();
293     }, 1500);
294   }
295   mtrack_footer_set_and_wait();
296 });
297  
298
299 // from file.php
300
301
302 // from head -- probably for reports only..
303
304  
305 $(document).ready(function() {
306          
307       $.tablesorter.addParser({
308         id: 'priority',
309         is: function(s) {
310           // don't auto-detect
311           return false;
312         },
313         format: function(s) {
314             if (typeof(priorities[s]) != 'undefined') {
315                 return priorities[s];
316             }
317             return s;
318         },
319         type: 'numeric'
320       });
321       
322       $.tablesorter.addParser({
323         id: 'severity',
324         is: function(s) {
325           // don't auto-detect
326           return false;
327         },
328         format: function(s) {
329             if (typeof(severities[s]) != 'undefined') {
330                 return severities[s];
331             }
332             return s;
333         },
334         type: 'numeric'
335     });
336 });
337
338 // from wiki..
339
340 $(document).ready(function(){
341   $('ul.wikitree').treeview({
342     collapsed: true,
343     persist: "location"
344   });
345 });
346