final move of files
[web.mtrack] / MTrackWeb / templates / images / js / mtrack.ticket.js
1 //<script type="text/javascript">
2 /*
3 mtrack = {
4     
5     showdiff : function(tx, part, target) {
6         var d = $('#' + target)[0];
7         if (d.getAttribute('current') == tx+'?'+part) {
8             d.innerHTML = '';
9             d.setAttribute('current', '') ;
10             return;
11         }
12          d.innerHTML = '&#160;Loading...';
13         
14         d.setAttribute('current', tx+'?'+part) ;
15
16         
17         $('#' + target).load(  ABSWEB + 'jschangeset.php' + tx + '?part=' + part );
18     }
19     
20     
21 }
22 */
23 var formChanged = 0;
24 var id;
25 var issue_tid_null;
26 var viewblock;
27 var view_off;
28 var view_pos;
29 var editblock;
30 var edit_off;
31 var edit_pos;
32 var commentblock;
33
34 // from ticket.php
35
36
37 function show_comment_form()
38 {
39     
40     
41     // hide stuff first.
42     //viewblock.css('position', view_pos);
43     //viewblock.css('top', view_off.top);
44     $("#comment-submit-buttons").hide();
45     $(".mtrack-make-comment").hide();
46     viewblock.hide();
47     
48     // show stuff next.
49     
50     $("#update-issue-desc").show()
51     $("#comment-container").show();
52     // what's this about...
53     $("#edit-comment-parent").append($("#comment-area"));
54     $("#comment-area").show();
55      
56     
57     
58     
59     editblock.show();
60     //edit_off = editblock.offset();
61     //edit_pos = editblock.css('position');
62     $("#description").focus();
63
64     
65     //compute_floats();
66 }
67 function show_edit_form()
68 {
69     //view_off = viewblock.offset();
70     //view_pos = viewblock.css('position');
71     //
72     //if (view_off) {
73     //    viewblock.css('position', view_pos);
74     //    viewblock.css('top', view_off.top);
75     //}
76
77     $("#issue-desc").hide();
78     $("#comment-submit-buttons").hide();
79     $(".mtrack-make-comment").hide();
80     $("#comment-container").hide();
81     viewblock.hide();
82     
83     $("#update-issue-desc").show()
84      $("#edit-issue-desc").show();
85     //$("#edit-comment-parent").append($("#comment-area"));
86     
87     //$("#comment-area").show();
88     
89     $("#description").focus();
90
91     editblock.show();
92     //edit_off = editblock.offset();
93     //edit_pos = editblock.css('position');
94     
95     
96     
97     //compute_floats();
98 }
99 function cancel_form_changes()
100 {
101     if (formChanged) {
102         document.location.href = document.location.href;
103         return false;
104     }
105
106     //editblock.css('position', edit_pos);
107     //editblock.css('top', edit_off.top);
108     editblock.hide();
109     viewblock.show();
110
111     $("#tktedit").each(function(){
112         // reset form
113         this.reset();
114     });
115     // notify asm select of change
116     $("select[multiple]").change();
117     $("#edit-issue-desc").hide();
118     $("#update-issue-desc").hide()
119     $("#original-comment-parent").append($("#comment-area"));
120     $("#comment-submit-buttons").show();
121
122     if (id != 'new') { 
123         $("#comment-area").hide();
124         $(".mtrack-make-comment").show();
125     } 
126     $("#issue-desc").show();
127     formChanged = false;
128     //compute_floats();
129
130     return false;
131 }
132 /*
133
134 function compute_floats() // disabled at present..
135 {
136    return;
137    if ($(viewblock).is(':visible')) {
138       view_off = viewblock.offset();
139     if ($(this).scrollTop() > view_off.top) {
140       viewblock.css('position', 'fixed');
141       viewblock.css('top', '0px');
142       viewblock.addClass('button-float-floating');
143     } else {
144       viewblock.css('position', view_pos);
145       viewblock.css('top', view_off.top);
146       viewblock.removeClass('button-float-floating');
147     }
148   }
149   if ($(editblock).is(':visible')) {
150     edit_off = editblock.offset();
151     if ($(this).scrollTop() > edit_off.top) {
152       editblock.css('position', 'fixed');
153       editblock.css('top', '0px');
154       editblock.addClass('button-float-floating');
155     } else if ($(this).scrollTop() < edit_off.top + editblock.height() - $(this).height()) {
156       editblock.css('position', 'fixed');
157       editblock.css('top', $(this).height() - editblock.outerHeight());
158       editblock.addClass('button-float-floating');
159     } else {
160       editblock.css('position', edit_pos);
161       editblock.css('top', edit_off.top);
162       editblock.removeClass('button-float-floating');
163     }
164   }
165 }
166 */
167
168 var mtrack_ticked_loaded = false;
169 $(document).ready(function()
170 {
171     
172     if (mtrack_ticked_loaded) {
173         return;
174     }
175     mtrack_ticked_loaded = true;
176     
177     viewblock = $('#tkt-view-button-block');
178     editblock = $('#tkt-edit-button-block');
179     
180     if (typeof(tid) == 'undefined') {
181         return; // not a ticket page..
182        }
183     
184     
185     
186     if (!tid){
187         show_edit_form();
188         $('#tkt-edit-button-block .mtrack-edit-cancel').hide();
189     }   
190    // $(window).scroll(function () {
191    //   compute_floats();
192    // });
193
194     
195     if (tid) {
196         // load the events..
197         $('#events-list').load( baseURL + '/Events/' + tid, function() {
198             $('abbr.timeinterval').timeago();
199             $('.ticketchangeinfo').hide();
200             
201             $('.ticketevent-expand').click(function() {
202                 var n = this.id.split('-').pop();
203                 var target = "[id='ticketchangeinfo-" + n + "']";
204                 var loadit = $(target).is(":hidden") && !$(target)[0].getAttribute('loaded');
205                  
206                  
207                 $(target).toggle(100);
208                 
209                 
210                 if (loadit && n.match(/\./)) {
211                     
212                     $(target)[0].innerHTML = '&#160;Loading...';
213         
214                     $(target)[0].setAttribute('loaded', 'true');
215                     $(target).load(  baseURL + '/Changeset/' + this.title + '?nowrap=1');
216                 }
217                 
218                 
219             })
220             
221         }) ;
222         
223         // load the watchers..
224         new mtrack.watch({
225             objname : 'ticket',
226             objid : tid,
227             domid : 'watch-list'
228         });
229          
230     }
231     
232     $(".mtrack-edit-desc").click(
233       function() {
234         show_edit_form();
235         return false;
236       }
237     );
238     
239     
240     $("input[type=radio]").click(
241       function() {
242         if (this.value == 'fixed') {
243           $("#changelog-container").show();
244         } else {
245           $("#changelog-container").hide();
246         }
247       }
248     );
249
250     $(":input").change(function() {
251         formChanged = true;
252     });
253     
254     
255     $("textarea").keyup(function() {
256       // This is here because IE doesn't seem to reliably trigger the
257       // change event with textareas
258         formChanged = true;
259     });
260     
261     // dialogs..
262     
263     $("#confirmCancelDialog").dialog({
264           autoOpen: false,
265           bgiframe: true,
266           resizable: false,
267           modal: true,
268           buttons: {
269             'Discard': function() {
270               $(this).dialog('close');
271               cancel_form_changes();
272             },
273             'Keep': function() {
274               $(this).dialog('close');
275             }
276           }
277     });
278     
279     $("#noCommentDialog").dialog({
280           autoOpen: false,
281           bgiframe: true,
282           resizable: false,
283           modal: true,
284           buttons: {
285             'OK': function() {
286               $(this).dialog('close');
287               $("#comment").focus();
288             }
289           }
290     });
291     $("#noSummaryDialog").dialog({
292           autoOpen: false,
293           bgiframe: true,
294           resizable: false,
295           modal: true,
296           buttons: {
297             'OK': function() {
298               $(this).dialog('close');
299               $("#summary").focus();
300             }
301           }
302     });
303
304
305     $(".mtrack-edit-cancel").click(
306           function() {
307             if (formChanged) {
308               $("#confirmCancelDialog").dialog('open');
309               return false;
310             } else {
311               return cancel_form_changes();
312             }
313           }
314     );
315     
316     
317     $(".mtrack-make-comment").click(
318           function() {
319             show_comment_form();
320             $("#comment").focus();
321             return false;
322           }
323     );
324
325     $(".mtrack-button-submit").click(function(){
326
327          
328         if ($("#summary").val() == '') {
329
330             $("#summary").addClass('error');
331             $("#noSummaryDialog").dialog('open');
332             return false;
333
334         } else {
335
336             if (formChanged == false && $("#comment").val() == '') {
337                 $("#comment").addClass('error');
338                 $("#noCommentDialog").dialog('open');
339                 return false;
340             }
341
342         }
343
344     });
345
346     $("#comment").keydown(function(){
347         $("#comment").removeClass('error');
348     });
349
350     $("#summary").keydown(function(){
351         $("#summary").removeClass('error');
352     });
353
354     if (issue_tid_null) {
355         $("#summary").focus();
356
357     }
358     $('#button-show-overflow').click(function() {
359           $('#show-overflow').hide('blind');
360           $('#ticketcommentsoverflow').show('clip');
361           return false;
362         });
363 });