1bez.ctl.task = function() { 2 3 jQuery('.bez_commcause_delete_prompt').click('on', function (event) { 4 if (!window.confirm(LANG.plugins.bez.remove_confirm)) { 5 event.preventDefault(); 6 } 7 }); 8 9 var $task_form = jQuery('.bez_task_form'); 10 11 if ($task_form.length > 0) { 12 //date picker 13 jQuery("input[name=plan_date]").datepicker({ 14 dateFormat: "yy-mm-dd" 15 }); 16 if (jQuery("input[name=all_day_event]").is(":checked")) { 17 jQuery('#task_datapair').hide(); 18 } 19 jQuery("input[name=all_day_event]").on('change', function() { 20 if (jQuery(this).is(":checked")) { 21 jQuery('#task_datapair').hide(); 22 } else { 23 jQuery('#task_datapair').show(); 24 } 25 }); 26 27 //time picker 28 jQuery('#task_datapair .time').timepicker({ 29 'showDuration': true, 30 'timeFormat': 'H:i' 31 }); 32 var timeDatepair = new Datepair(jQuery('#task_datapair').get(0)); 33 bez.rich_text_editor($task_form.find('textarea'), $task_form.find('.bez_toolbar')); 34 } 35 36 if (jQuery('#reason').length > 0) { 37 jQuery('#no_evaluation').on('change', function() { 38 if (jQuery(this).prop('checked') === true) { 39 jQuery('#reason').prop('disabled', true).hide(); 40 jQuery('.bez_reason_toolbar').hide(); 41 } else { 42 jQuery('#reason').prop('disabled', false).show(); 43 jQuery('.bez_reason_toolbar').show(); 44 } 45 46 }); 47 bez.rich_text_editor(jQuery('#reason'), jQuery('.bez_reason_toolbar')); 48 } 49 50 if (jQuery('.bez_metaform').length > 0) { 51 var tooltips = jQuery('.bez_metaform').find("input, select").tooltip({ 52 position: { 53 my: "left top", 54 at: "right+5 top-5", 55 collision: "none" 56 } 57 }); 58 jQuery.validate({ 59 form: '.bez_metaform', 60 inlineErrorMessageCallback: function($input, errorMessage, config) { 61 if ($input.tooltip("instance") === undefined) { 62 return false; 63 } 64 65 if (errorMessage) { 66 //customDisplayInlineErrorMessage($input, errorMessage); 67 $input.attr('title', errorMessage); 68 $input.tooltip("open"); 69 } else { 70 //customRemoveInlineError($input); 71 $input.tooltip("disable"); 72 } 73 return false; // prevent default behaviour 74 } 75 }); 76 77 jQuery("input[name=date], input[name=close_date]").datepicker({ 78 dateFormat: "yy-mm-dd" 79 }); 80 } 81 82 var $bez_comment_form = jQuery('.bez_comment_form'); 83 if ($bez_comment_form.length > 0) { 84 //textareas 85 var $textarea = $bez_comment_form.find("textarea"); 86 var $do_button = $bez_comment_form.find("button[value=task_do]"); 87 var $reopen_button = $bez_comment_form.find("button[value=task_reopen]"); 88 89 var $header = $bez_comment_form.find(".bez_toolbar"); 90 bez.rich_text_editor($textarea, $header); 91 92 $textarea.on('input', function() { 93 "use strict"; 94 if (jQuery(this).val().length > 0) { 95 if ($do_button.length > 0) { 96 $do_button.text(LANG.plugins.bez.comment_and_do_task); 97 } else { 98 $reopen_button.text(LANG.plugins.bez.comment_and_reopen_task); 99 } 100 } else { 101 if ($do_button.length > 0) { 102 $do_button.text(LANG.plugins.bez.do_task); 103 } else { 104 $reopen_button.text(LANG.plugins.bez.reopen_task); 105 } 106 } 107 }); 108 } 109 110 //tooltips 111 jQuery(document).tooltip({ 112 items: '#issue_participants a[title]', 113 position: { 114 my: "left top+15", 115 at: "left bottom", 116 collision: "flipfit" 117 }, 118 content: function() { 119 var $this = jQuery(this); 120 name = $this.find('.bez_name').text(), 121 content = '<div style="margin-bottom: 3px;">'+name+'</div>'; 122 $this.find('.bez_awesome').each(function() { 123 var $this = jQuery(this); 124 content += '<div>'+$this.get(0).outerHTML+' '+$this.attr('title')+'</div>'; 125 }); 126 127 return content; 128 } 129 }); 130 131 jQuery("#plugin__bez_do_task_button").click(function() { 132 "use strict"; 133 jQuery("button[value=task_do], button[value=task_reopen]").effect("highlight"); 134 }); 135 136 //INVITE USERS 137 jQuery.widget( "custom.combobox", { 138 _create: function() { 139 this.wrapper = jQuery( "<span>" ) 140 .addClass( "custom-combobox" ) 141 .insertAfter( this.element ); 142 143 this.element.hide(); 144 this._createAutocomplete(); 145 this._createShowAllButton(); 146 }, 147 148 _createAutocomplete: function() { 149 var selected = this.element.children( ":selected" ), 150 value = selected.val() ? selected.text() : ""; 151 152 this.input = jQuery( "<input>" ) 153 .appendTo( this.wrapper ) 154 .val( value ) 155 .attr( "title", "" ) 156 .addClass( "custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left" ) 157 .autocomplete({ 158 delay: 0, 159 minLength: 0, 160 source: jQuery.proxy( this, "_source" ) 161 }) 162 .tooltip({ 163 classes: { 164 "ui-tooltip": "ui-state-highlight" 165 } 166 }); 167 168 this._on( this.input, { 169 autocompleteselect: function( event, ui ) { 170 ui.item.option.selected = true; 171 this._trigger( "select", event, { 172 item: ui.item.option 173 }); 174 }, 175 176 autocompletechange: "_removeIfInvalid" 177 }); 178 }, 179 180 _createShowAllButton: function() { 181 var input = this.input, 182 wasOpen = false; 183 184 jQuery( "<a>" ) 185 .attr( "tabIndex", -1 ) 186 .attr( "title", LANG.plugins.bez.combobox_show_all_items ) 187 .tooltip() 188 .appendTo( this.wrapper ) 189 .button({ 190 icons: { 191 primary: "ui-icon-triangle-1-s" 192 }, 193 text: false 194 }) 195 .removeClass( "ui-corner-all" ) 196 .addClass( "custom-combobox-toggle ui-corner-right" ) 197 .on( "mousedown", function() { 198 wasOpen = input.autocomplete( "widget" ).is( ":visible" ); 199 }) 200 .on( "click", function() { 201 input.trigger( "focus" ); 202 203 // Close if already visible 204 if ( wasOpen ) { 205 return; 206 } 207 208 // Pass empty string as value to search for, displaying all results 209 input.autocomplete( "search", "" ); 210 }); 211 }, 212 213 _source: function( request, response ) { 214 var matcher = new RegExp( jQuery.ui.autocomplete.escapeRegex(request.term), "i" ); 215 response( this.element.children( "option" ).map(function() { 216 var text = jQuery( this ).text(); 217 if ( this.value && ( !request.term || matcher.test(text) ) ) { 218 219 return { 220 label: text, 221 value: text, 222 option: this 223 }; 224 } 225 }) ); 226 }, 227 228 _removeIfInvalid: function( event, ui ) { 229 230 // Selected an item, nothing to do 231 if ( ui.item ) { 232 return; 233 } 234 235 // Search for a match (case-insensitive) 236 var value = this.input.val(), 237 valueLowerCase = value.toLowerCase(), 238 valid = false; 239 this.element.children( "option" ).each(function() { 240 if ( jQuery( this ).text().toLowerCase() === valueLowerCase ) { 241 this.selected = valid = true; 242 return false; 243 } 244 }); 245 246 // Found a match, nothing to do 247 if ( valid ) { 248 return; 249 } 250 251 // Remove invalid value 252 this.input 253 .val( "" ) 254 .attr( "title", value + " " + LANG.plugins.bez.combobox_did_not_match ) 255 .tooltip( "open" ); 256 this.element.val( "" ); 257 this._delay(function() { 258 this.input.tooltip( "close" ).attr( "title", "" ); 259 }, 2500 ); 260 this.input.autocomplete( "instance" ).term = ""; 261 }, 262 263 _destroy: function() { 264 this.wrapper.remove(); 265 this.element.show(); 266 } 267 }); 268 269 jQuery( "#bez_invite_users select" ).combobox(); 270 //INVITE 271}; 272