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