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 //show/hide opinion 29 var $form = jQuery("#bez_issue_report.update"); 30 if ($form.length > 0) { 31 var $coordinator = $form.find("select[name=coordinator]"); 32 var $opinion_row = $form.find("textarea[name=opinion]").parents("div[class=row]"); 33 var $status_row = $form.find("label[for=state]").parents("div[class=row]"); 34 var $state = $form.find("input[name=state]"); 35 36 /*state.length == 0 -> nie możemy zmieniać statusu*/ 37 if ($state.length == 0) 38 $opinion_row.hide(); 39 40 var cval = $coordinator.val(); 41 if (cval == '-proposal' || cval == '-rejected' ) { 42 $status_row.hide(); 43 $opinion_row.hide(); 44 } 45 46 47 $coordinator.change(function () { 48 var cval = $coordinator.val(); 49 if (cval == '-proposal' || cval == '-rejected') { 50 $status_row.hide(); 51 $opinion_row.hide(); 52 } else { 53 $status_row.show(); 54 if ($form.find("input[name=state]:checked").val() == "1") 55 $opinion_row.show(); 56 } 57 }); 58 59 60 if ($form.find("input[name=state]:checked").val() == "0") 61 $opinion_row.hide(); 62 63 $state.change(function() { 64 $this = jQuery(this); 65 if ($this.val() == "0") 66 $opinion_row.hide(); 67 else 68 $opinion_row.show(); 69 }); 70 } 71 72 //show/hide reason 73 $reason_row = jQuery("#bez_tasks textarea[name=reason]").parents("div[class=row]"); 74 75 if ($reason_row.length > 0) { 76 $select = jQuery("#bez_tasks select[name=state]"); 77 78 if ($select.val() == "0" || $select.val() == "1") 79 $reason_row.hide(); 80 81 $select.change(function() { 82 if (jQuery(this).val() == "0" || jQuery(this).val() == "1") 83 $reason_row.hide(); 84 else 85 $reason_row.show(); 86 }); 87 } 88 89 var show = function() { 90 jQuery(this).siblings(".bds_block_content").show(); 91 jQuery(this).find(".toggle").css("background-image", "url(lib/plugins/bds/images/expanded.png)"); 92 }; 93 var hide = function() { 94 jQuery(this).siblings(".bds_block_content").hide(); 95 jQuery(this).find(".toggle").css("background-image", "url(lib/plugins/bds/images/collapsed.png)"); 96 }; 97 98 jQuery(".bds_block") 99 .each(function() { 100 $h1 = jQuery(this).find("h1").html( 101 function(index, oldhtml) { 102 return '<span class="toggle">'+oldhtml+'</span>'; 103 }); 104 105 $h1.find(".toggle").css( 106 { 107 'background': 'url("lib/plugins/bds/images/collapsed.png") no-repeat scroll 4px 50% rgba(0, 0, 0, 0)', 108 'border': 'medium none', 109 'border-radius': '0.3em', 110 'box-shadow': '0.1em 0.1em 0.3em 0 #BBBBBB', 111 'color': '#222222', 112 'padding': '0.3em 0.5em 0.3em 20px', 113 'text-shadow': '0.1em 0.1em #FCFCFC', 114 'cursor': 'pointer' 115 }); 116 117 118 var hash = window.location.hash.substring(1); 119 if (hash.indexOf("k") === 0) { 120 var showed = "bez_comments"; 121 } else if (hash.indexOf("p") === 0) { 122 var showed = "bez_causes"; 123 } else if (hash.indexOf("z") === 0) { 124 var showed = "bez_tasks"; 125 } else if (hash === "bds_change_issue") { 126 var showed = "bds_change_issue"; 127 } 128 129 if (jQuery(this).attr("id") === showed) { 130 jQuery(this).find(".toggle").css("background-image", "url(lib/plugins/bds/images/expanded.png)"); 131 jQuery(this).find("h1").toggle(hide, show); 132 } else { 133 jQuery(this).find(".bds_block_content").hide(); 134 jQuery(this).find("h1").toggle(show, hide); 135 } 136 }); 137 jQuery(".bds_block .history_anchor").click(function() { 138 show.call(jQuery("#bds_history h1")[0]); 139 }); 140 141 //entities sort 142 jQuery("#entities_form input[type=button]").click(function() { 143 var textarea = jQuery(this).parents("form").find("textarea"); 144 var lines = jQuery.trim(textarea.val()).split("\n"); 145 lines.sort(); 146 textarea.val(lines.join("\n")); 147 }); 148 149}); 150