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 93 //tooltips 94 jQuery(document).tooltip({ 95 items: '#issue_participants a[title]', 96 position: { 97 my: "left top+15", 98 at: "left bottom", 99 collision: "flipfit" 100 }, 101 content: function() { 102 var $this = jQuery(this); 103 name = $this.find('.bez_name').text(), 104 content = '<div style="margin-bottom: 3px;">'+name+'</div>'; 105 $this.find('.bez_awesome').each(function() { 106 var $this = jQuery(this); 107 content += '<div>'+$this.get(0).outerHTML+' '+$this.attr('title')+'</div>'; 108 }); 109 110 return content; 111 } 112 }); 113 114 jQuery("#plugin__bez_do_task_button").click(function() { 115 "use strict"; 116 jQuery("button[value=task_do], button[value=task_reopen]").effect("highlight"); 117 }); 118 119 //INVITE USERS 120 jQuery.widget( "custom.combobox", { 121 _create: function() { 122 this.wrapper = jQuery( "<span>" ) 123 .addClass( "custom-combobox" ) 124 .insertAfter( this.element ); 125 126 this.element.hide(); 127 this._createAutocomplete(); 128 this._createShowAllButton(); 129 }, 130 131 _createAutocomplete: function() { 132 var selected = this.element.children( ":selected" ), 133 value = selected.val() ? selected.text() : ""; 134 135 this.input = jQuery( "<input>" ) 136 .appendTo( this.wrapper ) 137 .val( value ) 138 .attr( "title", "" ) 139 .addClass( "custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left" ) 140 .autocomplete({ 141 delay: 0, 142 minLength: 0, 143 source: jQuery.proxy( this, "_source" ) 144 }) 145 .tooltip({ 146 classes: { 147 "ui-tooltip": "ui-state-highlight" 148 } 149 }); 150 151 this._on( this.input, { 152 autocompleteselect: function( event, ui ) { 153 ui.item.option.selected = true; 154 this._trigger( "select", event, { 155 item: ui.item.option 156 }); 157 }, 158 159 autocompletechange: "_removeIfInvalid" 160 }); 161 }, 162 163 _createShowAllButton: function() { 164 var input = this.input, 165 wasOpen = false; 166 167 jQuery( "<a>" ) 168 .attr( "tabIndex", -1 ) 169 .attr( "title", LANG.plugins.bez.combobox_show_all_items ) 170 .tooltip() 171 .appendTo( this.wrapper ) 172 .button({ 173 icons: { 174 primary: "ui-icon-triangle-1-s" 175 }, 176 text: false 177 }) 178 .removeClass( "ui-corner-all" ) 179 .addClass( "custom-combobox-toggle ui-corner-right" ) 180 .on( "mousedown", function() { 181 wasOpen = input.autocomplete( "widget" ).is( ":visible" ); 182 }) 183 .on( "click", function() { 184 input.trigger( "focus" ); 185 186 // Close if already visible 187 if ( wasOpen ) { 188 return; 189 } 190 191 // Pass empty string as value to search for, displaying all results 192 input.autocomplete( "search", "" ); 193 }); 194 }, 195 196 _source: function( request, response ) { 197 var matcher = new RegExp( jQuery.ui.autocomplete.escapeRegex(request.term), "i" ); 198 response( this.element.children( "option" ).map(function() { 199 var text = jQuery( this ).text(); 200 if ( this.value && ( !request.term || matcher.test(text) ) ) { 201 202 return { 203 label: text, 204 value: text, 205 option: this 206 }; 207 } 208 }) ); 209 }, 210 211 _removeIfInvalid: function( event, ui ) { 212 213 // Selected an item, nothing to do 214 if ( ui.item ) { 215 return; 216 } 217 218 // Search for a match (case-insensitive) 219 var value = this.input.val(), 220 valueLowerCase = value.toLowerCase(), 221 valid = false; 222 this.element.children( "option" ).each(function() { 223 if ( jQuery( this ).text().toLowerCase() === valueLowerCase ) { 224 this.selected = valid = true; 225 return false; 226 } 227 }); 228 229 // Found a match, nothing to do 230 if ( valid ) { 231 return; 232 } 233 234 // Remove invalid value 235 this.input 236 .val( "" ) 237 .attr( "title", value + " " + LANG.plugins.bez.combobox_did_not_match ) 238 .tooltip( "open" ); 239 this.element.val( "" ); 240 this._delay(function() { 241 this.input.tooltip( "close" ).attr( "title", "" ); 242 }, 2500 ); 243 this.input.autocomplete( "instance" ).term = ""; 244 }, 245 246 _destroy: function() { 247 this.wrapper.remove(); 248 this.element.show(); 249 } 250 }); 251 252 jQuery( "#bez_invite_users select" ).combobox(); 253 //INVITE 254}; 255