1 2bez.ctl.thread = function() { 3 4 jQuery('.bez_commcause_delete_prompt').click('on', function (event) { 5 if (!window.confirm(LANG.plugins.bez.remove_confirm)) { 6 event.preventDefault(); 7 } 8 }); 9 10 var $bez_comment_form = jQuery('.bez_comment_form'), 11 $tabs = $bez_comment_form.find('.bez_tabs'); 12 if ($tabs.length > 0) { 13 var $links = $tabs.find('a'), 14 $active = $tabs.find('li.active a'), 15 active = $active[0], 16 $comment_type_input = jQuery(".bez_comment_type"), 17 $cause_type_div = jQuery(".bez_cause_type"); 18 19 var setActive = function($a) { 20 $tabs.find('.active').removeClass('active'); 21 $a.parent().addClass('active'); 22 }; 23 24 var activateComment = function () { 25 $comment_type_input.removeAttr("disabled"); 26 $cause_type_div.hide(); 27 $cause_type_div.find("input").attr("disabled", "disabled"); 28 29 $bez_comment_form.removeClass('bez_cause'); 30 }; 31 32 var activateCause = function() { 33 $comment_type_input.attr("disabled", "disabled"); 34 $cause_type_div.show(); 35 $cause_type_div.find("input").removeAttr("disabled"); 36 37 $bez_comment_form.addClass('bez_cause'); 38 }; 39 40 if (active.hash === '#comment') { 41 setActive($active); 42 activateComment(); 43 } else if (active.hash === '#cause') { 44 setActive($active); 45 activateCause(); 46 } 47 48 49 $tabs.on('click', 'a', function (e) { 50 e.preventDefault(); 51 setActive(jQuery(this)); 52 }); 53 54 $tabs.on('click', 'a[href="#comment"]', activateComment); 55 $tabs.on('click', 'a[href="#cause"]', activateCause); 56 } 57 if ($bez_comment_form.length > 0) { 58 //textareas 59 var $textarea = $bez_comment_form.find("textarea"); 60 var $header = $bez_comment_form.find(".bez_toolbar"); 61 bez.rich_text_editor($textarea, $header); 62 } 63 64 //show/hide comments 65 var $show_comments = jQuery(".bez_show_comments"), 66 $hide_comments = jQuery(".bez_hide_comments"); 67 68 var bez_show_comments = function() { 69 $show_comments.hide(); 70 $hide_comments.show(); 71 localStorage.setItem('comments_are_hidden', '0'); 72 jQuery('.bez_type_0').show(); 73 }; 74 75 var bez_hide_comments = function() { 76 $hide_comments.hide(); 77 $show_comments.show(); 78 localStorage.setItem('comments_are_hidden', '1'); 79 jQuery('.bez_type_0').hide(); 80 }; 81 82 var comments_are_hidden = localStorage.getItem('comments_are_hidden'); 83 if (comments_are_hidden === null || comments_are_hidden === '0') { 84 bez_show_comments(); 85 } else { 86 bez_hide_comments(); 87 } 88 89 $show_comments.on('click', function(e) { e.preventDefault(); bez_show_comments() }); 90 $hide_comments.on('click', function(e) { e.preventDefault(); bez_hide_comments() }); 91 92 if (jQuery('.bez_task_form').length > 0) { 93 var $task_form = jQuery('.bez_task_form'); 94 //date picker 95 jQuery("input[name=plan_date]").datepicker({ 96 dateFormat: "yy-mm-dd" 97 }); 98 if (jQuery("input[name=all_day_event]").is(":checked")) { 99 jQuery('#task_datapair').hide(); 100 } 101 jQuery("input[name=all_day_event]").on('change', function() { 102 if (jQuery(this).is(":checked")) { 103 jQuery('#task_datapair').hide(); 104 } else { 105 jQuery('#task_datapair').show(); 106 } 107 }); 108 109 //time picker 110 jQuery('#task_datapair .time').timepicker({ 111 'showDuration': true, 112 'timeFormat': 'H:i' 113 }); 114 var timeDatepair = new Datepair(jQuery('#task_datapair').get(0)); 115 116 //cost 117 //~ jQuery('input[name=cost]').spinner({ 118 //~ min: 0, 119 //~ max: 100000, 120 //~ step: 50 121 //~ }); 122 123 bez.rich_text_editor($task_form.find('textarea'), $task_form.find('.bez_toolbar')); 124 125 //~ $task_form.validetta({ 126 127 //~ }); 128 } 129 130 if (jQuery('.bez_metaform').length > 0) { 131 var tooltips = jQuery('.bez_metaform').find("input, select").tooltip({ 132 position: { 133 my: "left top", 134 at: "right+5 top-5", 135 collision: "none" 136 } 137 }); 138 jQuery.validate({ 139 form: '.bez_metaform', 140 inlineErrorMessageCallback: function($input, errorMessage, config) { 141 if ($input.tooltip("instance") === undefined) { 142 return false; 143 } 144 145 if (errorMessage) { 146 //customDisplayInlineErrorMessage($input, errorMessage); 147 $input.attr('title', errorMessage); 148 $input.tooltip("open"); 149 } else { 150 //customRemoveInlineError($input); 151 $input.tooltip("disable"); 152 } 153 return false; // prevent default behaviour 154 } 155 }); 156 157 //~ if (jQuery('input[name="close_date"]').length > 0) { 158 //~ console.log(jQuery('.bez_timebox')); 159 //~ //https://github.com/jonthornton/Datepair.js#jquery-plugin 160 //~ jQuery('.bez_timebox').datepair({ 161 //~ parseDate: function (el) { 162 //~ var val = jQuery(el).datepicker('getDate'); 163 //~ if (!val) { 164 //~ return null; 165 //~ } 166 //~ var utc = new Date(val); 167 //~ return utc && new Date(utc.getTime() + (utc.getTimezoneOffset() * 60000)); 168 //~ }, 169 //~ updateDate: function (el, v) { 170 //~ jQuery(el).datepicker('setDate', new Date(v.getTime() - (v.getTimezoneOffset() * 60000))); 171 //~ } 172 //~ }); 173 //~ } 174 175 jQuery("input[name=date], input[name=close_date], input[name=last_mod], input[name=last_activity_date]").datepicker({ 176 dateFormat: "yy-mm-dd" 177 }); 178 } 179 180 if (jQuery('#opinion').length > 0) { 181 bez.rich_text_editor(jQuery('#opinion'), jQuery('.bez_opinion_toolbar')); 182 } 183 184 if (jQuery('#reason').length > 0) { 185 jQuery('#no_evaluation').on('change', function() { 186 if (jQuery(this).prop('checked') === true) { 187 jQuery('#reason').prop('disabled', true).hide(); 188 jQuery('.bez_reason_toolbar').hide(); 189 } else { 190 jQuery('#reason').prop('disabled', false).show(); 191 jQuery('.bez_reason_toolbar').show(); 192 } 193 194 }); 195 bez.rich_text_editor(jQuery('#reason'), jQuery('.bez_reason_toolbar')); 196 } 197 198 //tooltips 199 jQuery(document).tooltip({ 200 items: '#issue_participants a[title]', 201 position: { 202 my: "left top+15", 203 at: "left bottom", 204 collision: "flipfit" 205 }, 206 content: function() { 207 var $this = jQuery(this); 208 name = $this.find('.bez_name').text(), 209 content = '<div style="margin-bottom: 3px;">'+name+'</div>'; 210 $this.find('.bez_awesome').each(function() { 211 var $this = jQuery(this); 212 content += '<div>'+$this.get(0).outerHTML+' '+$this.attr('title')+'</div>'; 213 }); 214 215 return content; 216 } 217 }); 218 219 220 //INVITE USERS 221 jQuery.widget( "custom.combobox", { 222 _create: function() { 223 this.wrapper = jQuery( "<span>" ) 224 .addClass( "custom-combobox" ) 225 .insertAfter( this.element ); 226 227 this.element.hide(); 228 this._createAutocomplete(); 229 this._createShowAllButton(); 230 }, 231 232 _createAutocomplete: function() { 233 var selected = this.element.children( ":selected" ), 234 value = selected.val() ? selected.text() : ""; 235 236 this.input = jQuery( "<input>" ) 237 .appendTo( this.wrapper ) 238 .val( value ) 239 .attr( "title", "" ) 240 .addClass( "custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left" ) 241 .autocomplete({ 242 delay: 0, 243 minLength: 0, 244 source: jQuery.proxy( this, "_source" ) 245 }) 246 .tooltip({ 247 classes: { 248 "ui-tooltip": "ui-state-highlight" 249 } 250 }); 251 252 this._on( this.input, { 253 autocompleteselect: function( event, ui ) { 254 ui.item.option.selected = true; 255 this._trigger( "select", event, { 256 item: ui.item.option 257 }); 258 }, 259 260 autocompletechange: "_removeIfInvalid" 261 }); 262 }, 263 264 _createShowAllButton: function() { 265 var input = this.input, 266 wasOpen = false; 267 268 jQuery( "<a>" ) 269 .attr( "tabIndex", -1 ) 270 .attr( "title", LANG.plugins.bez.combobox_show_all_items ) 271 .tooltip() 272 .appendTo( this.wrapper ) 273 .button({ 274 icons: { 275 primary: "ui-icon-triangle-1-s" 276 }, 277 text: false 278 }) 279 .removeClass( "ui-corner-all" ) 280 .addClass( "custom-combobox-toggle ui-corner-right" ) 281 .on( "mousedown", function() { 282 wasOpen = input.autocomplete( "widget" ).is( ":visible" ); 283 }) 284 .on( "click", function() { 285 input.trigger( "focus" ); 286 287 // Close if already visible 288 if ( wasOpen ) { 289 return; 290 } 291 292 // Pass empty string as value to search for, displaying all results 293 input.autocomplete( "search", "" ); 294 }); 295 }, 296 297 _source: function( request, response ) { 298 var matcher = new RegExp( jQuery.ui.autocomplete.escapeRegex(request.term), "i" ); 299 response( this.element.children( "option" ).map(function() { 300 var text = jQuery( this ).text(); 301 if ( this.value && ( !request.term || matcher.test(text) ) ) { 302 303 return { 304 label: text, 305 value: text, 306 option: this 307 }; 308 } 309 }) ); 310 }, 311 312 _removeIfInvalid: function( event, ui ) { 313 314 // Selected an item, nothing to do 315 if ( ui.item ) { 316 return; 317 } 318 319 // Search for a match (case-insensitive) 320 var value = this.input.val(), 321 valueLowerCase = value.toLowerCase(), 322 valid = false; 323 this.element.children( "option" ).each(function() { 324 if ( jQuery( this ).text().toLowerCase() === valueLowerCase ) { 325 this.selected = valid = true; 326 return false; 327 } 328 }); 329 330 // Found a match, nothing to do 331 if ( valid ) { 332 return; 333 } 334 335 // Remove invalid value 336 this.input 337 .val( "" ) 338 .attr( "title", value + " " + LANG.plugins.bez.combobox_did_not_match ) 339 .tooltip( "open" ); 340 this.element.val( "" ); 341 this._delay(function() { 342 this.input.tooltip( "close" ).attr( "title", "" ); 343 }, 2500 ); 344 this.input.autocomplete( "instance" ).term = ""; 345 }, 346 347 _destroy: function() { 348 this.wrapper.remove(); 349 this.element.show(); 350 } 351 }); 352 353 jQuery( "#bez_invite_users select" ).combobox(); 354 //INVITE 355}; 356