|
92 | 92 | hideOnMouseOut : true
|
93 | 93 | },
|
94 | 94 | url_set : undefined,
|
| 95 | + customValues : undefined, |
95 | 96 | onChange: undefined // callback function each time value changes
|
96 | 97 | };
|
97 | 98 |
|
|
156 | 157 | };
|
157 | 158 |
|
158 | 159 | var combinations = {
|
159 |
| - "minute" : /^(\*\s){4}\*$/, // "* * * * *" |
160 |
| - "hour" : /^\d{1,2}\s(\*\s){3}\*$/, // "? * * * *" |
161 |
| - "day" : /^(\d{1,2}\s){2}(\*\s){2}\*$/, // "? ? * * *" |
| 160 | + "minute" : /^(\*\s){4}\*$/, // "* * * * *" |
| 161 | + "hour" : /^\d{1,2}\s(\*\s){3}\*$/, // "? * * * *" |
| 162 | + "day" : /^(\d{1,2}\s){2}(\*\s){2}\*$/, // "? ? * * *" |
162 | 163 | "week" : /^(\d{1,2}\s){2}(\*\s){2}\d{1,2}$/, // "? ? * * ?"
|
163 |
| - "month" : /^(\d{1,2}\s){3}\*\s\*$/, // "? ? ? * *" |
164 |
| - "year" : /^(\d{1,2}\s){4}\*$/ // "? ? ? ? *" |
| 164 | + "month" : /^(\d{1,2}\s){3}\*\s\*$/, // "? ? ? * *" |
| 165 | + "year" : /^(\d{1,2}\s){4}\*$/ // "? ? ? ? *" |
165 | 166 | };
|
166 |
| - |
| 167 | + |
167 | 168 | // ------------------ internal functions ---------------
|
168 | 169 | function defined(obj) {
|
169 | 170 | if (typeof obj == "undefined") { return false; }
|
170 | 171 | else { return true; }
|
171 | 172 | }
|
172 | 173 |
|
| 174 | + function undefinedOrObject(obj) { |
| 175 | + return (!defined(obj) || typeof obj == "object") |
| 176 | + } |
| 177 | + |
173 | 178 | function getCronType(cron_str) {
|
174 | 179 | // check format of initial cron value
|
175 | 180 | var valid_cron = /^((\d{1,2}|\*)\s){4}(\d{1,2}|\*)$/
|
|
203 | 208 |
|
204 | 209 | function hasError(c, o) {
|
205 | 210 | if (!defined(getCronType(o.initial))) { return true; }
|
| 211 | + if (!undefinedOrObject(o.customValues)) { return true; } |
206 | 212 | return false;
|
207 | 213 | }
|
208 | 214 |
|
209 | 215 | function getCurrentValue(c) {
|
210 | 216 | var b = c.data("block");
|
211 | 217 | var min = hour = day = month = dow = "*";
|
212 |
| - |
213 |
| - switch (b["period"].find("select").val()) { |
| 218 | + var selectedPeriod = b["period"].find("select").val(); |
| 219 | + switch (selectedPeriod) { |
| 220 | + case "minute": |
| 221 | + break; |
| 222 | + |
214 | 223 | case "hour":
|
215 | 224 | min = b["mins"].find("select").val();
|
216 | 225 | break;
|
|
238 | 247 | day = b["dom"].find("select").val();
|
239 | 248 | month = b["month"].find("select").val();
|
240 | 249 | break;
|
| 250 | + |
| 251 | + default: |
| 252 | + // we assume this only happens when customValues is set |
| 253 | + return selectedPeriod; |
241 | 254 | }
|
242 | 255 | return [min, hour, day, month, dow].join(" ");
|
243 | 256 | }
|
|
264 | 277 |
|
265 | 278 | // ---- define select boxes in the right order -----
|
266 | 279 |
|
267 |
| - var block = [] |
| 280 | + var block = [], custom_periods = "", cv = o.customValues; |
| 281 | + if (defined(cv)) { // prepend custom values if specified |
| 282 | + for (var key in cv) { |
| 283 | + custom_periods += "<option value='" + cv[key] + "'>" + key + "</option>\n"; |
| 284 | + } |
| 285 | + } |
268 | 286 | block["period"] = $("<span class='cron-period'>"
|
269 |
| - + "Every <select name='cron-period'>" + str_opt_period |
270 |
| - + "</select> </span>") |
| 287 | + + "Every <select name='cron-period'>" + custom_periods |
| 288 | + + str_opt_period + "</select> </span>") |
271 | 289 | .appendTo(this)
|
272 | 290 | .find("select")
|
273 | 291 | .bind("change.cron", event_handlers.periodChanged)
|
|
395 | 413 | var event_handlers = {
|
396 | 414 | periodChanged : function() {
|
397 | 415 | var root = $(this).data("root");
|
398 |
| - var block = root.data("block"); |
399 |
| - var b = toDisplay[$(this).val()]; |
400 |
| - |
401 |
| - root.find("span.cron-block").hide(); // first, hide all blocks |
402 |
| - for (var i = 0; i < b.length; i++) { |
403 |
| - block[b[i]].show(); |
| 416 | + var block = root.data("block"), |
| 417 | + opt = root.data("options"); |
| 418 | + var period = $(this).val(); |
| 419 | + root.find("span.cron-block").hide(); // first, hide all blocks |
| 420 | + if (toDisplay.hasOwnProperty(period)) { // not custom value |
| 421 | + var b = toDisplay[$(this).val()]; |
| 422 | + for (var i = 0; i < b.length; i++) { |
| 423 | + block[b[i]].show(); |
| 424 | + } |
404 | 425 | }
|
405 | 426 | },
|
406 | 427 |
|
|
0 commit comments