1bds = {}; 2 3bds.gup = function (name) { 4 name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); 5 var regexS = "[\\?&]" + name + "=([^&#]*)"; 6 var regex = new RegExp(regexS); 7 var results = regex.exec(window.location.href); 8 if (results == null) 9 return ""; 10 else 11 return results[1]; 12}; 13 14jQuery(document).ready(function() { 15 var ids = ['description', 'cause', 'content', 'task', 'reason', 'opinion']; 16 17 for (var i = 0; i < ids.length; i++) { 18 var textarea = jQuery("#" + ids[i]); 19 if (textarea.length > 0) { 20 textarea.before('<div id="toolbar'+ids[i]+'"></div>'); 21 if (textarea.parents("form").find("input[name=id]").length === 0) { 22 textarea.before('<input type="hidden" name="id" value="'+bds.gup('id')+'" />'); 23 } 24 initToolbar('toolbar'+ids[i], ids[i], toolbar); 25 } 26 } 27 28 var $conf = jQuery("#bez_removal_confirm"); 29 $conf.find(".no").click(function(e) { 30 e.preventDefault(); 31 $conf.hide(); 32 }); 33 34 //delete_button 35 $delete_buts = jQuery("#bez_comments, #bez_causes").find(".bez_delete_button"); 36 jQuery("body").bind("click", function (e) { 37 var $target = jQuery(e.target); 38 if (!$target.is($delete_buts)) 39 $conf.hide(); 40 }); 41 42 $delete_buts.each(function() { 43 jQuery(this).click(function(e) { 44 e.preventDefault(); 45 var $click = jQuery(this); 46 var off = $click.offset(); 47 $conf.appendTo("body"); 48 $conf.css({ 49 'position': 'absolute', 50 'left': off.left-$conf.width()+$click.width(), 51 'top': off.top+2, 52 }); 53 $conf.find("input").unbind("click"); 54 $conf.find("input").bind("click", function(e) { 55 e.preventDefault(); 56 window.location = $click.attr("href"); 57 }); 58 $conf.show(); 59 }); 60 }); 61 62 //show/hide opinion 63 /*var $form = jQuery("#bez_issue_report.update"); 64 if ($form.length > 0) { 65 var $coordinator = $form.find("select[name=coordinator]"); 66 var $opinion_row = $form.find("textarea[name=opinion]").parents("div[class=row]"); 67 var $status_row = $form.find("label[for=state]").parents("div[class=row]"); 68 var $state = $form.find("input[name=state]"); 69 70 //state.length == 0 -> nie możemy zmieniać statusu 71 if ($state.length == 0) 72 $opinion_row.hide(); 73 74 var cval = $coordinator.val(); 75 if (cval == '-proposal' || cval == '-rejected' ) { 76 $status_row.hide(); 77 $opinion_row.hide(); 78 } 79 80 81 $coordinator.change(function () { 82 var cval = $coordinator.val(); 83 if (cval == '-proposal' || cval == '-rejected') { 84 $status_row.hide(); 85 $opinion_row.hide(); 86 } else { 87 $status_row.show(); 88 if ($form.find("input[name=state]:checked").val() == "1") 89 $opinion_row.show(); 90 } 91 }); 92 93 94 if ($form.find("input[name=state]:checked").val() == "0") 95 $opinion_row.hide(); 96 97 $state.change(function() { 98 $this = jQuery(this); 99 if ($this.val() == "0") 100 $opinion_row.hide(); 101 else 102 $opinion_row.show(); 103 }); 104 }*/ 105 106 //show/hide reason 107 /*$reason_row = jQuery(".bez_task_form textarea[name=reason]").parents("div[class=row]"); 108 109 if ($reason_row.length > 0) { 110 $select = jQuery(".bez_task_form select[name=state]"); 111 $action = jQuery(".bez_task_form input[name=action]"); 112 113 if ($select.val() == "0" || ($select.val() == "1" && $action.val() != "2")) 114 $reason_row.hide(); 115 116 var $label = jQuery(".bez_task_form label[for=reason]"); 117 var text = $label.text(); 118 console.log(text); 119 var res = text.match(/[a-z ]+/gi); 120 121 if ($select.val() == "1") 122 $label.text(res[1]+":"); 123 else 124 $label.text(res[0]+":"); 125 126 $select.change(function() { 127 if (jQuery(this).val() == "0" || (jQuery(this).val() == "1" && $action.val() != "2")) 128 $reason_row.hide(); 129 else 130 $reason_row.show(); 131 132 if (jQuery(this).val() == "1" && $action.val() == "2") 133 $label.text(res[1]+":"); 134 else 135 $label.text(res[0]+":"); 136 }); 137 } 138 139 var show = function() { 140 jQuery(this).siblings(".bds_block_content").show(); 141 jQuery(this).find(".toggle").css("background-image", "url(lib/plugins/bez/images/expanded.png)"); 142 }; 143 var hide = function() { 144 jQuery(this).siblings(".bds_block_content").hide(); 145 jQuery(this).find(".toggle").css("background-image", "url(lib/plugins/bez/images/collapsed.png)"); 146 }; 147 148 /*jQuery(".bds_block") 149 .each(function() { 150 $h1 = jQuery(this).find("h1").html( 151 function(index, oldhtml) { 152 return '<span class="toggle">'+oldhtml+'</span>'; 153 }); 154 155 $h1.find(".toggle").css( 156 { 157 'background': 'url("lib/plugins/bez/images/collapsed.png") no-repeat scroll 4px 50% rgba(0, 0, 0, 0)', 158 'border': 'medium none', 159 'border-radius': '0.3em', 160 'box-shadow': '0.1em 0.1em 0.3em 0 #BBBBBB', 161 'color': '#222222', 162 'padding': '0.3em 0.5em 0.3em 20px', 163 'text-shadow': '0.1em 0.1em #FCFCFC', 164 'cursor': 'pointer' 165 }); 166 167 168 var hash = window.location.hash.substring(1); 169 if (hash.indexOf("k") === 0) { 170 var showed = "bez_comments"; 171 } else if (hash.indexOf("p") === 0) { 172 var showed = "bez_causes"; 173 } else if (hash.indexOf("z") === 0) { 174 var showed = "bez_tasks"; 175 } else if (hash === "bds_change_issue") { 176 var showed = "bds_change_issue"; 177 } 178 179 if (jQuery(this).attr("id") === showed) { 180 jQuery(this).find(".toggle").css("background-image", "url(lib/plugins/bez/images/expanded.png)"); 181 jQuery(this).find("h1").toggle(hide, show); 182 } else { 183 jQuery(this).find(".bds_block_content").hide(); 184 jQuery(this).find("h1").toggle(show, hide); 185 } 186 }); 187 jQuery(".bds_block .history_anchor").click(function() { 188 show.call(jQuery("#bds_history h1")[0]); 189 });*/ 190 191 //entities sort 192 jQuery("#entities_form input[type=button]").click(function() { 193 var textarea = jQuery(this).parents("form").find("textarea"); 194 var lines = jQuery.trim(textarea.val()).split("\n"); 195 lines.sort(); 196 textarea.val(lines.join("\n")); 197 }); 198 199 /*Zmiana kolorów podczas zmiany priorytetów*/ 200 var $issue_rep = jQuery("#bez_issue_report"); 201 if ($issue_rep.length > 0) { 202 var colors = {'0': '#B0D2B6', '1': '#dd9', '2': '#F0AFAD'}; 203 var bgcolors = {'0': '#eeF6F0', '1': '#ffd', '2': '#F8e8E8'}; 204 var $form = $issue_rep.find(".bds_form"); 205 var $prior = $issue_rep.find(".priorities"); 206 207 $prior.find("input").hide(); 208 $prior.find("label").css({ 209 'margin-right': '5px', 210 'padding' : '5px', 211 'background-color' : '#F7F7F0', 212 'border' : '2px solid', 213 'border-bottom' : '0', 214 'border-top-left-radius' : '5px', 215 'border-top-right-radius' : '5px', 216 'position' : 'relative', 217 'top' : '-1px' 218 }); 219 220 $form.css({ 221 'border': '2px solid', 222 'border-top-left-radius': '0', 223 'position' : 'relative', 224 'z-index': '100' 225 }); 226 227 228 $prior.find("label").each(function() { 229 var $this = jQuery(this); 230 var ind = $this.index(); 231 $this.css('border-color', colors[ind]); 232 $this.css('background-color', bgcolors[ind]); 233 }); 234 235 var change_color = function() { 236 var color = $prior.find("input:checked").val(); 237 $form.css('border-color', colors[color]); 238 $form.css('background-color', bgcolors[color]); 239 /*ustaw*/ 240 $prior.find("label").css('z-index', '0'); 241 $prior.find("input:checked").parents("label").css('z-index', '1000'); 242 }; 243 change_color(); 244 245 $prior.change(function() { 246 change_color(); 247 }); 248 } 249 250 jQuery("input[name=plan_date]").datepicker({ 251 dateFormat: "yy-mm-dd" 252 }); 253 if (jQuery("input[name=all_day_event]").is(":checked")) { 254 jQuery("input[name=start_time]").prop( "disabled", true ); 255 jQuery("input[name=finish_time]").prop( "disabled", true ); 256 } 257 jQuery("input[name=all_day_event]").on('change', function() { 258 if (jQuery(this).is(":checked")) { 259 jQuery("input[name=start_time]").prop( "disabled", true ); 260 jQuery("input[name=finish_time]").prop( "disabled", true ); 261 } else { 262 jQuery("input[name=start_time]").prop( "disabled", false ); 263 jQuery("input[name=finish_time]").prop( "disabled", false ); 264 } 265 }); 266 //timepicker 267 268 var hours = ["00:30", "1:00", "1:30", "2:00", "2:30", "3:00", "3:30", "4:00", 269 "4:30", "5:00", "5:30", "6:00", "6:30", "7:00", "7:30", "8:00", "8:30", "9:00", "9:30", "10:00", "10:30", "11:00", "11:30", 270 "12:00", "12:30", "13:00", "13:30", "14:00", "14:30", "15:00", "15:30", 271 "16:00", "16:30", "17:00", "17:30", "18:00", "18:30", "19:00", "19:30", 272 "20:00", "20:30", "21:00", "21:30", "22:00", "22:30", "23:00", "23:30", 273 "24:00" ]; 274 275 //ukrywanie niepotrzebnych godzin zależnie od godziny rozpoczęcia 276 var hide_unneeded_hours = function ($this) { 277 hour = $this.val(); 278 var index = hours.indexOf(hour); 279 280 //finish time lis 281 var $finish_time_li = jQuery("#bez_timepicker_finish_time li"); 282 $finish_time_li.show(); 283 $finish_time_li.eq(index).prevAll().hide(); 284 285 if (jQuery("input[name=finish_time]").val() == '') 286 jQuery("input[name=finish_time]").val(hour); 287 } 288 jQuery("input[name=start_time]").blur(function () { 289 hide_unneeded_hours(jQuery(this)); 290 }); 291 292 293 var autoFill = function (hour) { 294 if (hour.indexOf(":") === -1) 295 hour += ":00"; 296 else if (hour.match(/^[0-9]{1,2}:$/g)) 297 hour += "00"; 298 else if (hour.match(/^[0-9]{1,2}:(0|3)$/g)) 299 hour += "0"; 300 else if (hour.match(/^[0-9]{1,2}:(1|2)$/g)) 301 hour = hour.slice(0,-1)+"00"; 302 else if (hour.match(/^[0-9]{1,2}:[4-9]$/g)) 303 hour = hour.slice(0,-1)+"30"; 304 else if (hour.match(/^[0-9]{1,2}:(0|3)[1-9]$/g)) 305 hour = hour.slice(0,-1)+"0"; 306 return hour; 307 } 308 var listScrool = function($list, hour) { 309 hour = autoFill(hour); 310 var index = hours.indexOf(hour); 311 if (index == -1) index = 0; 312 $li = $list.find("li:first"); 313 //hidden lis 314 var $hid_lis = $list.find("li:hidden"); 315 $list.scrollTop((index - $hid_lis.length - 1) * $li.outerHeight()); 316 $list.find("li").removeClass("selected"); 317 $list.find("li").eq(index).addClass("selected"); 318 319 } 320 321 jQuery(".bez_timepicker").each(function() { 322 var $this = jQuery(this); 323 324 var id = "bez_timepicker_"+$this.attr("name"); 325 $wrapper = jQuery(document.createElement('div')) 326 .css({ 'position': 'absolute', 327 }).addClass('bez_timepicker_wrapper') 328 .hide().attr("id", id).appendTo("body"); 329 330 var offset = $this.offset(); 331 offset.top += $this.outerHeight() + 1; 332 $wrapper.offset(offset); 333 334 $ul = jQuery(document.createElement("ul")).appendTo($wrapper); 335 336 337 for (h in hours) { 338 hour = hours[h]; 339 $li = jQuery(document.createElement("li")); 340 $li.text(hour); 341 $li.on('mousedown', function(event) { 342 var id = jQuery(this).parents("div").attr("id"); 343 var name = id.replace("bez_timepicker_", ''); 344 jQuery("input[name="+name+"]").val(jQuery(this).text()); 345 346 jQuery(this).siblings().removeClass("selected"); 347 jQuery(this).addClass("selected"); 348 }); 349 $ul.append($li); 350 } 351 352 353 /*if ($this.val() != "") 354 listScrool($ul, $this.val());*/ 355 356 $this.focus(function() { 357 var $this = jQuery(this); 358 var id = "bez_timepicker_"+$this.attr("name"); 359 $wrapper = jQuery("#"+id); 360 $wrapper.show(); 361 listScrool($wrapper, $this.val()); 362 363 }); 364 $this.blur(function() { 365 var $this = jQuery(this); 366 var id = "bez_timepicker_"+$this.attr("name"); 367 $wrapper = jQuery("#"+id); 368 $wrapper.hide(); 369 }); 370 $this.change(function() { 371 var $this = jQuery(this); 372 var id = "bez_timepicker_"+$this.attr("name"); 373 $wrapper = jQuery("#"+id); 374 $this.val($wrapper.find("li.selected").text()); 375 $wrapper.hide(); 376 }); 377 $this.on('keyup', function() { 378 var $this = jQuery(this); 379 var id = "bez_timepicker_"+$this.attr("name"); 380 $wrapper = jQuery("#"+id); 381 listScrool($wrapper, $this.val()); 382 }); 383 }); 384 hide_unneeded_hours(jQuery("input[name=start_time]")); 385 386 387 //task plan field 388 jQuery("input[name=task_plan]").change(function() { 389 $this = jQuery(this); 390 console.log($this); 391 if ($this.is(":checked")) 392 jQuery(".task_plan_field").show(); 393 else 394 jQuery(".task_plan_field").hide(); 395 }); 396 if (jQuery("input[name=task_plan]").is(":checked")) 397 jQuery(".task_plan_field").show(); 398 else 399 jQuery(".task_plan_field").hide(); 400 401 402 //bez_show_desc 403 jQuery(".bez_desc_row").hide(); 404 jQuery("#bez_show_desc").on('click', function(e) { 405 if (jQuery(this).find(".show").is(":visible")) { 406 jQuery(".bez_desc_row").show(); 407 jQuery(this).find(".hide").show(); 408 jQuery(this).find(".show").hide(); 409 } else { 410 jQuery(".bez_desc_row").hide(); 411 jQuery(this).find(".hide").hide(); 412 jQuery(this).find(".show").show(); 413 } 414 e.preventDefault(); 415 }); 416 417 /*ukrywanie zakmniętych zadań i formularza dodawania nowych zadań*/ 418 /*var $tasks = jQuery("#bez_tasks .bds_block_content"); 419 if ($tasks.length > 0) { 420 var hidden = 0; 421 $tasks.find(".task").each(function () { 422 var $this = jQuery(this); 423 if ( ! $this.hasClass("opened")) { 424 $this.hide(); 425 hidden++; 426 } 427 }); 428 if (hidden > 0) { 429 $button = $tasks.find(".show_tasks_hidden"); 430 console.log($button); 431 $button.show(); 432 $button.click(function() { 433 $tasks.find(".task").show(); 434 jQuery(this).hide(); 435 }); 436 } 437 //$form = $tasks.find("form"); 438 } 439 jQuery(".bez_task_form").each(function () { 440 $this = jQuery(this); 441 if ( ! $this.hasClass('update')) { 442 $this.hide(); 443 $add_task = $this.parent().find(".add_task"); 444 $add_task.show(); 445 $add_task.click(function(e) { 446 $add_task_btn = jQuery(this); 447 var form = $add_task_btn.parent().find("form"); 448 form.show(); 449 $add_task_btn.hide(); 450 e.preventDefault(); 451 }); 452 } 453 });*/ 454}); 455