]> git.wh0rd.org - tt-rss.git/blame - modules/pref-labels.php
rework label editor to use dijit.form validation
[tt-rss.git] / modules / pref-labels.php
CommitLineData
ef8be8ea 1<?php
ef8be8ea 2 function module_pref_labels($link) {
ef8be8ea 3
b4e75b2a 4 $subop = $_REQUEST["subop"];
ef8be8ea 5
fb8b2153
AD
6 if ($subop == "edit") {
7 $label_id = db_escape_string($_REQUEST['id']);
8
fb8b2153
AD
9 $result = db_query($link, "SELECT * FROM ttrss_labels2 WHERE
10 id = '$label_id' AND owner_uid = " . $_SESSION["uid"]);
11
12 $line = db_fetch_assoc($result);
13
48b05a29
AD
14# print "<form id=\"label_edit_form\" name=\"label_edit_form\"
15# onsubmit=\"return false;\">";
018caf6f 16
48b05a29
AD
17 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"$label_id\">";
18 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-labels\">";
19 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"save\">";
018caf6f 20
fb8b2153
AD
21 print "<div class=\"dlgSec\">".__("Caption")."</div>";
22
23 print "<div class=\"dlgSecCont\">";
24
3851fd56
AD
25 $fg_color = $line['fg_color'];
26 $bg_color = $line['bg_color'];
27
28 print "<span class=\"labelColorIndicator\" id=\"label-editor-indicator\" style='color : $fg_color; background-color : $bg_color'>&alpha;</span>";
29
48b05a29
AD
30 print "<input style=\"font-size : 16px\" name=\"caption\"
31 dojoType=\"dijit.form.ValidationTextBox\"
32 required=\"true\"
018caf6f 33 value=\"".htmlspecialchars($line['caption'])."\">";
fb8b2153
AD
34
35 print "</div>";
018caf6f 36 print "<div class=\"dlgSec\">" . __("Colors") . "</div>";
fb8b2153
AD
37 print "<div class=\"dlgSecCont\">";
38
2f88ca8c 39 print "<table cellspacing=\"0\">";
fb8b2153 40
018caf6f 41 print "<tr><td>".__("Foreground:")."</td><td>".__("Background:").
fb8b2153
AD
42 "</td></tr>";
43
2f88ca8c 44 print "<tr><td style='padding-right : 10px'>";
fb8b2153 45
48b05a29
AD
46 print "<input dojoType=\"dijit.form.TextBox\"
47 style=\"display : none\" id=\"labelEdit_fgColor\"
48 name=\"fg_color\" value=\"$fg_color\">";
49 print "<input dojoType=\"dijit.form.TextBox\"
50 style=\"display : none\" id=\"labelEdit_bgColor\"
51 name=\"bg_color\" value=\"$bg_color\">";
018caf6f 52
fb8b2153
AD
53 print "<div dojoType=\"dijit.ColorPalette\">
54 <script type=\"dojo/method\" event=\"onChange\" args=\"fg_color\">
48b05a29 55 dijit.byId(\"labelEdit_fgColor\").attr('value', fg_color);
3851fd56 56 $('label-editor-indicator').setStyle({color: fg_color});
fb8b2153
AD
57 </script>
58 </div>";
59 print "</div>";
60
61 print "</td><td>";
62
63 print "<div dojoType=\"dijit.ColorPalette\">
64 <script type=\"dojo/method\" event=\"onChange\" args=\"bg_color\">
48b05a29 65 dijit.byId(\"labelEdit_bgColor\").attr('value', bg_color);
3851fd56 66 $('label-editor-indicator').setStyle({backgroundColor: bg_color});
fb8b2153
AD
67 </script>
68 </div>";
69 print "</div>";
70
71 print "</td></tr></table>";
72 print "</div>";
73
48b05a29 74# print "</form>";
018caf6f
AD
75
76 print "<div class=\"dlgButtons\">";
48b05a29 77 print "<button onclick=\"dijit.byId('labelEditDlg').execute()\">".
018caf6f 78 __('Save')."</button>";
48b05a29 79 print "<button onclick=\"dijit.byId('labelEditDlg').hide()\">".
018caf6f 80 __('Cancel')."</button>";
fb8b2153
AD
81 print "</div>";
82
fb8b2153
AD
83 return;
84 }
85
86 if ($subop == "getlabeltree") {
87 $root = array();
88 $root['id'] = 'root';
89 $root['name'] = __('Labels');
90 $root['items'] = array();
91
92 $result = db_query($link, "SELECT *
93 FROM ttrss_labels2
94 WHERE owner_uid = ".$_SESSION["uid"]."
95 ORDER BY caption");
96
97 while ($line = db_fetch_assoc($result)) {
98 $label = array();
99 $label['id'] = 'LABEL:' . $line['id'];
100 $label['bare_id'] = $line['id'];
101 $label['name'] = $line['caption'];
102 $label['fg_color'] = $line['fg_color'];
103 $label['bg_color'] = $line['bg_color'];
104 $label['type'] = 'label';
105 $label['checkbox'] = false;
106
107 array_push($root['items'], $label);
108 }
109
110 $fl = array();
111 $fl['identifier'] = 'id';
112 $fl['label'] = 'name';
113 $fl['items'] = array($root);
114
115 print json_encode($fl);
116 return;
117 }
118
b8776a07
AD
119 if ($subop == "color-set") {
120 $kind = db_escape_string($_REQUEST["kind"]);
121 $ids = split(',', db_escape_string($_REQUEST["ids"]));
122 $color = db_escape_string($_REQUEST["color"]);
b6ba48c1
AD
123 $fg = db_escape_string($_REQUEST["fg"]);
124 $bg = db_escape_string($_REQUEST["bg"]);
b8776a07
AD
125
126 foreach ($ids as $id) {
b6ba48c1
AD
127
128 if ($kind == "fg" || $kind == "bg") {
129 db_query($link, "UPDATE ttrss_labels2 SET
130 ${kind}_color = '$color' WHERE id = '$id'
131 AND owner_uid = " . $_SESSION["uid"]);
132 } else {
133 db_query($link, "UPDATE ttrss_labels2 SET
134 fg_color = '$fg', bg_color = '$bg' WHERE id = '$id'
135 AND owner_uid = " . $_SESSION["uid"]);
136 }
905ff52a
AD
137
138 $caption = db_escape_string(label_find_caption($link, $id, $_SESSION["uid"]));
139
140 /* Remove cached data */
141
142 db_query($link, "UPDATE ttrss_user_entries SET label_cache = ''
143 WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $_SESSION["uid"]);
144
b8776a07
AD
145 }
146
aec9df48
AD
147 return;
148 }
149
150 if ($subop == "color-reset") {
151 $ids = split(',', db_escape_string($_REQUEST["ids"]));
152
153 foreach ($ids as $id) {
154 db_query($link, "UPDATE ttrss_labels2 SET
155 fg_color = '', bg_color = '' WHERE id = '$id'
156 AND owner_uid = " . $_SESSION["uid"]);
905ff52a
AD
157
158 $caption = db_escape_string(label_find_caption($link, $id, $_SESSION["uid"]));
159
160 /* Remove cached data */
161
162 db_query($link, "UPDATE ttrss_user_entries SET label_cache = ''
163 WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $_SESSION["uid"]);
aec9df48
AD
164 }
165
b8776a07
AD
166 }
167
ceb30ba4 168 if ($subop == "save") {
071ec48f 169
ceb30ba4 170 $id = db_escape_string($_REQUEST["id"]);
018caf6f 171 $caption = db_escape_string(trim($_REQUEST["caption"]));
071ec48f 172
ceb30ba4 173 db_query($link, "BEGIN");
10fa6615 174
ceb30ba4
AD
175 $result = db_query($link, "SELECT caption FROM ttrss_labels2
176 WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]);
ef8be8ea 177
ceb30ba4
AD
178 if (db_num_rows($result) != 0) {
179 $old_caption = db_fetch_result($result, 0, "caption");
a4919a16 180
ceb30ba4
AD
181 $result = db_query($link, "SELECT id FROM ttrss_labels2
182 WHERE caption = '$caption' AND owner_uid = ". $_SESSION["uid"]);
ef8be8ea 183
ceb30ba4
AD
184 if (db_num_rows($result) == 0) {
185 if ($caption) {
186 $result = db_query($link, "UPDATE ttrss_labels2 SET
187 caption = '$caption' WHERE id = '$id' AND
188 owner_uid = " . $_SESSION["uid"]);
ef8be8ea 189
ceb30ba4 190 /* Update filters that reference label being renamed */
ef8be8ea 191
7a13338b
AD
192 $old_caption = db_escape_string($old_caption);
193
ceb30ba4
AD
194 db_query($link, "UPDATE ttrss_filters SET
195 action_param = '$caption' WHERE action_param = '$old_caption'
196 AND action_id = 7
197 AND owner_uid = " . $_SESSION["uid"]);
ef8be8ea 198
9c5e85fe 199 print $_REQUEST["value"];
625acd1c
AD
200 } else {
201 print $old_caption;
ceb30ba4
AD
202 }
203 } else {
204 print $old_caption;
ef8be8ea 205 }
ef8be8ea
AD
206 }
207
ceb30ba4 208 db_query($link, "COMMIT");
ef8be8ea
AD
209
210 return;
211 }
212
ef8be8ea
AD
213 if ($subop == "remove") {
214
b4e75b2a 215 $ids = split(",", db_escape_string($_REQUEST["ids"]));
ef8be8ea 216
f6f7817d 217 foreach ($ids as $id) {
1380f8ee 218 label_remove($link, $id, $_SESSION["uid"]);
ef8be8ea 219 }
f6f7817d 220
ef8be8ea
AD
221 }
222
223 if ($subop == "add") {
b4e75b2a 224 $caption = db_escape_string($_REQUEST["caption"]);
1c31e190 225 $output = db_escape_string($_REQUEST["output"]);
ef8be8ea 226
ceb30ba4 227 if ($caption) {
caf1f12f 228
6b2ee18d 229 if (label_create($link, $caption)) {
1c31e190 230 if (!$output) {
d69fa6d6 231 print T_sprintf("Created label <b>%s</b>", htmlspecialchars($caption));
1c31e190 232 }
ceb30ba4 233 }
6b2ee18d 234
1c31e190
AD
235 if ($output == "select") {
236 header("Content-Type: text/xml");
237
10249c41 238 print "<rpc-reply><payload>";
1c31e190
AD
239
240 print_label_select($link, "select_label",
241 $caption, "");
242
10249c41 243 print "</payload></rpc-reply>";
1c31e190 244 }
5e6f933a
AD
245 }
246
247 return;
ef8be8ea
AD
248 }
249
b4e75b2a 250 $sort = db_escape_string($_REQUEST["sort"]);
ef8be8ea
AD
251
252 if (!$sort || $sort == "undefined") {
ceb30ba4 253 $sort = "caption";
ef8be8ea
AD
254 }
255
b4e75b2a 256 $label_search = db_escape_string($_REQUEST["search"]);
112d2aec 257
b4e75b2a 258 if (array_key_exists("search", $_REQUEST)) {
112d2aec
AD
259 $_SESSION["prefs_label_search"] = $label_search;
260 } else {
261 $label_search = $_SESSION["prefs_label_search"];
262 }
263
8df7184c
AD
264 print "<div id=\"pref-label-wrap\" dojoType=\"dijit.layout.BorderContainer\" gutters=\"false\">";
265 print "<div id=\"pref-label-header\" dojoType=\"dijit.layout.ContentPane\" region=\"top\">";
266 print "<div id=\"pref-label-toolbar\" dojoType=\"dijit.Toolbar\">";
267
d69fa6d6
AD
268 print "<div dojoType=\"dijit.form.DropDownButton\">".
269 "<span>" . __('Select')."</span>";
270 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
fb8b2153 271 print "<div onclick=\"dijit.byId('labelTree').model.setAllChecked(true)\"
d69fa6d6 272 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
fb8b2153 273 print "<div onclick=\"dijit.byId('labelTree').model.setAllChecked(false)\"
d69fa6d6
AD
274 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
275 print "</div></div>";
276
1985a5e0
AD
277 print"<button dojoType=\"dijit.form.Button\" onclick=\"return addLabel()\">".
278 __('Create label')."</button dojoType=\"dijit.form.Button\"> ";
1e5548db 279
1985a5e0
AD
280 print "<button dojoType=\"dijit.form.Button\" onclick=\"removeSelectedLabels()\">".
281 __('Remove')."</button dojoType=\"dijit.form.Button\"> ";
1e5548db 282
1985a5e0
AD
283 print "<button dojoType=\"dijit.form.Button\" onclick=\"labelColorReset()\">".
284 __('Clear colors')."</button dojoType=\"dijit.form.Button\">";
1e5548db
AD
285
286
8df7184c
AD
287 print "</div>"; #toolbar
288 print "</div>"; #pane
289 print "<div id=\"pref-label-content\" dojoType=\"dijit.layout.ContentPane\" region=\"center\">";
ef8be8ea 290
fb8b2153
AD
291 print "<div id=\"labellistLoading\">
292 <img src='images/indicator_tiny.gif'>".
293 __("Loading, please wait...")."</div>";
294
295 print "<div dojoType=\"dojo.data.ItemFileWriteStore\" jsId=\"labelStore\"
296 url=\"backend.php?op=pref-labels&subop=getlabeltree\">
297 </div>
298 <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"labelModel\" store=\"labelStore\"
299 query=\"{id:'root'}\" rootId=\"root\"
300 childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\">
301 </div>
302 <div dojoType=\"fox.PrefLabelTree\" id=\"labelTree\"
303 model=\"labelModel\" openOnClick=\"true\">
304 <script type=\"dojo/method\" event=\"onLoad\" args=\"item\">
305 Element.hide(\"labellistLoading\");
306 </script>
307 </div>";
8df7184c
AD
308
309 print "</div>"; #pane
310 print "</div>"; #container
ef8be8ea 311 }
1d4a2918 312
ef8be8ea 313?>