xref: /plugin/bez/script.js (revision 5828f2289754e5b8a3f5e25e76b75716a673af6c)
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
251	/*ukrywanie zakmniętych zadań i formularza dodawania nowych zadań*/
252	/*var $tasks = jQuery("#bez_tasks .bds_block_content");
253	if ($tasks.length > 0) {
254		var hidden = 0;
255		$tasks.find(".task").each(function () {
256			var $this = jQuery(this);
257			if ( ! $this.hasClass("opened")) {
258				$this.hide();
259				hidden++;
260			}
261		});
262		if (hidden > 0) {
263			$button = $tasks.find(".show_tasks_hidden");
264			console.log($button);
265			$button.show();
266			$button.click(function() {
267				$tasks.find(".task").show();
268				jQuery(this).hide();
269			});
270		}
271		//$form = $tasks.find("form");
272	}
273	jQuery(".bez_task_form").each(function () {
274		$this = jQuery(this);
275		if ( ! $this.hasClass('update')) {
276			$this.hide();
277			$add_task = $this.parent().find(".add_task");
278			$add_task.show();
279			$add_task.click(function(e) {
280				$add_task_btn = jQuery(this);
281				var form = $add_task_btn.parent().find("form");
282				form.show();
283				$add_task_btn.hide();
284				e.preventDefault();
285			});
286		}
287	});*/
288});
289