xref: /plugin/bez/script.js (revision 8ce39bb5b30654760cfbf59af91c047a132979b7)
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_tasks textarea[name=reason]").parents("div[class=row]");
108
109	if ($reason_row.length > 0) {
110		$select = jQuery("#bez_tasks select[name=state]");
111
112		if ($select.val() == "0" || $select.val() == "1")
113			$reason_row.hide();
114
115		$select.change(function() {
116			if (jQuery(this).val() == "0" || jQuery(this).val() == "1")
117				$reason_row.hide();
118			else
119				$reason_row.show();
120		});
121	}
122
123	var show = function() {
124			jQuery(this).siblings(".bds_block_content").show();
125			jQuery(this).find(".toggle").css("background-image", "url(lib/plugins/bez/images/expanded.png)");
126		};
127	var hide = function() {
128			jQuery(this).siblings(".bds_block_content").hide();
129			jQuery(this).find(".toggle").css("background-image", "url(lib/plugins/bez/images/collapsed.png)");
130		};
131
132	jQuery(".bds_block")
133		.each(function() {
134			$h1 = jQuery(this).find("h1").html(
135				function(index, oldhtml) {
136					return '<span class="toggle">'+oldhtml+'</span>';
137				});
138
139			$h1.find(".toggle").css(
140				{
141					'background': 'url("lib/plugins/bez/images/collapsed.png") no-repeat scroll 4px 50% rgba(0, 0, 0, 0)',
142					'border': 'medium none',
143					'border-radius': '0.3em',
144					'box-shadow': '0.1em 0.1em 0.3em 0 #BBBBBB',
145					'color': '#222222',
146					'padding': '0.3em 0.5em 0.3em 20px',
147					'text-shadow': '0.1em 0.1em #FCFCFC',
148					'cursor': 'pointer'
149				});
150
151
152			var hash = window.location.hash.substring(1);
153			if (hash.indexOf("k") === 0) {
154				var showed = "bez_comments";
155			} else if (hash.indexOf("p") === 0) {
156				var showed = "bez_causes";
157			} else if (hash.indexOf("z") === 0) {
158				var showed = "bez_tasks";
159			} else if (hash === "bds_change_issue") {
160				var showed = "bds_change_issue";
161			}
162
163			if (jQuery(this).attr("id") === showed) {
164				jQuery(this).find(".toggle").css("background-image", "url(lib/plugins/bez/images/expanded.png)");
165				jQuery(this).find("h1").toggle(hide, show);
166			} else {
167				jQuery(this).find(".bds_block_content").hide();
168				jQuery(this).find("h1").toggle(show, hide);
169			}
170		});
171	jQuery(".bds_block .history_anchor").click(function() {
172		show.call(jQuery("#bds_history h1")[0]);
173	});
174
175	//entities sort
176	jQuery("#entities_form input[type=button]").click(function() {
177		var textarea = jQuery(this).parents("form").find("textarea");
178		var lines = jQuery.trim(textarea.val()).split("\n");
179		lines.sort();
180		textarea.val(lines.join("\n"));
181	});
182
183});
184