xref: /plugin/bez/script.js (revision 510f3b217af986987360986354207cda3b1fd3d2)
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	/*Zmiana kolorów podczas zmiany priorytetów*/
184	var $issue_rep = jQuery("#bez_issue_report");
185	if ($issue_rep.length > 0) {
186		var colors = {'0': '#B0D2B6', '1':  '#dd9', '2': '#F0AFAD'};
187		var bgcolors = {'0': '#eeF6F0', '1':  '#ffd', '2': '#F8e8E8'};
188		var $form = $issue_rep.find(".bds_form");
189		var $prior = $issue_rep.find(".priorities");
190
191		$prior.find("input").hide();
192		$prior.find("label").css({
193				'margin-right': '5px',
194				'padding' : '5px',
195				'background-color' : '#F7F7F0',
196				'border' : '2px solid',
197				'border-bottom' : '0',
198				'border-top-left-radius' : '5px',
199				'border-top-right-radius' : '5px',
200				'position' : 'relative',
201				'top' : '-1px'
202		});
203
204		$form.css({
205			'border': '2px solid',
206			'border-top-left-radius': '0',
207			'position' : 'relative',
208			'z-index': '100'
209		});
210
211
212		$prior.find("label").each(function() {
213			var $this = jQuery(this);
214			var ind = $this.index();
215			$this.css('border-color', colors[ind]);
216			$this.css('background-color', bgcolors[ind]);
217		});
218
219		var change_color = function() {
220			var color = $prior.find("input:checked").val();
221			$form.css('border-color', colors[color]);
222			$form.css('background-color', bgcolors[color]);
223			/*ustaw*/
224			$prior.find("label").css('z-index', '0');
225			$prior.find("input:checked").parents("label").css('z-index', '1000');
226		};
227		change_color();
228
229		$prior.change(function() {
230			change_color();
231		});
232	}
233
234
235	/*ukrywanie zakmniętych zadań i formularza dodawania nowych zadań*/
236	var $tasks = jQuery("#bez_tasks .bds_block_content");
237	if ($tasks.length > 0) {
238		var hidden = 0;
239		$tasks.find(".task").each(function () {
240			var $this = jQuery(this);
241			if ( ! $this.hasClass("opened")) {
242				$this.hide();
243				hidden++;
244			}
245		});
246		if (hidden > 0) {
247			$button = $tasks.find(".show_tasks_hidden");
248			console.log($button);
249			$button.show();
250			$button.click(function() {
251				$tasks.find(".task").show();
252				jQuery(this).hide();
253			});
254		}
255		//$form = $tasks.find("form");
256	}
257	jQuery("form.task_form").each(function () {
258		$this = jQuery(this);
259		if ( ! $this.hasClass('update')) {
260			$this.hide();
261			$add_task = $this.parent().find(".add_task");
262			$add_task.show();
263			$add_task.click(function(e) {
264				$add_task_btn = jQuery(this);
265				var form = $add_task_btn.parent().find("form");
266				form.show();
267				$add_task_btn.hide();
268				e.preventDefault();
269			});
270		}
271	});
272});
273