]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/modules/Schedulers/Schedulers.js
Release 6.5.0
[Github/sugarcrm.git] / jssource / src_files / modules / Schedulers / Schedulers.js
1 /*********************************************************************************
2  * SugarCRM Community Edition is a customer relationship management program developed by
3  * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
4  * 
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU Affero General Public License version 3 as published by the
7  * Free Software Foundation with the addition of the following permission added
8  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
9  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
10  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
11  * 
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
15  * details.
16  * 
17  * You should have received a copy of the GNU Affero General Public License along with
18  * this program; if not, see http://www.gnu.org/licenses or write to the Free
19  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  * 02110-1301 USA.
21  * 
22  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
23  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
24  * 
25  * The interactive user interfaces in modified source and object code versions
26  * of this program must display Appropriate Legal Notices, as required under
27  * Section 5 of the GNU Affero General Public License version 3.
28  * 
29  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
30  * these Appropriate Legal Notices must retain the display of the "Powered by
31  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
32  * technical reasons, the Appropriate Legal Notices must display the words
33  * "Powered by SugarCRM".
34  ********************************************************************************/
35
36
37
38 function checkFormPre(formId) {
39         validateCronInterval(formId);
40         var noError = check_form(formId);
41
42         if(noError) {
43                 return true;
44         } else {
45                 toggleAdv('true');
46                 return false;
47         }
48 }
49
50 function validateCronInterval(formId) {
51         var fieldIsValid = function(value, min, max) {
52                 var inRange = function(value, min, max) {
53                         return (value >= min && value <= max);
54                 }
55                 //Check for *
56                 if (value == "*") {
57                         return true;
58                 }
59                 //Check for interval syntax
60                 var result = /^\*\/(\d+)$/.exec(value);
61                 if (result && result[0] && inRange(result[1], min, max)) {
62                         return true;
63                 }
64                 //Check for ranges/lists
65                 var sets = value.split(',');
66                 var valid = true;
67                 for (var i = 0; i < sets.length; i++) {
68                         result = /^(\d+)(-(\d+))?$/.exec(sets[i])
69                         if (!result || !result[0] || !inRange(result[1], min, max) || (result[3] && !inRange(result[3], min, max))) {
70                                 return false;
71                         }
72                 }
73                 return true;
74         }
75         var cronFields = {
76                 mins:             {min:0, max:59},
77                 hours:            {min:0, max:23},
78                 day_of_month: {min:1, max:31},
79                 months:           {min:1, max:12},
80                 day_of_week:  {min:0, max:7}
81         }
82         var valid = true;
83         for (field in cronFields) {
84                 removeFromValidate(formId, field);
85                 if (document[formId][field] && !fieldIsValid(document[formId][field].value, cronFields[field].min, cronFields[field].max)) {
86                         valid = false;
87                         addToValidate(formId, field, 'error', true, "{$MOD.ERR_CRON_SYNTAX}");
88                 } else {
89                         addToValidate(formId, field, 'verified', true, "{$MOD.ERR_CRON_SYNTAX}");
90                 }
91         }
92         return valid;
93 }
94
95 function toggleAdv(onlyAdv) {
96         var thisForm = document.getElementById("EditView");
97         var crontab = document.getElementById("crontab");
98         var simple = document.getElementById("simple");
99         var adv = document.getElementById("advTable");
100         var use = document.getElementById("use_adv");
101
102         if(crontab.style.display == "none" || onlyAdv == 'true') { // show advanced
103                 crontab.style.display = "";
104                 adv.style.display = "";
105                 simple.style.display = "none";
106                 use.value = "true";
107         } else {
108                 crontab.style.display = "none";
109                 adv.style.display = "none";
110                 simple.style.display = "";
111                 use.value = "false";
112         }
113
114         for(i=0; i<thisForm.elements.length; i++) {
115                 if(thisForm.elements[i].disabled) {
116                         thisForm.elements[i].disabled = false;
117                 }
118         }
119 }
120
121 function allDays() {
122         var toggle = document.getElementById("all");
123         var m = document.getElementById("mon");
124         var t = document.getElementById("tue");
125         var w = document.getElementById("wed");
126         var h = document.getElementById("thu");
127         var f = document.getElementById("fri");
128         var s = document.getElementById("sat");
129         var u = document.getElementById("sun");
130
131         if(toggle.checked) {
132                 m.checked = true;
133                 t.checked = true;
134                 w.checked = true;
135                 h.checked = true;
136                 f.checked = true;
137                 s.checked = true;
138                 u.checked = true;
139         } else {
140                 m.checked = false;
141                 t.checked = false;
142                 w.checked = false;
143                 h.checked = false;
144                 f.checked = false;
145                 s.checked = false;
146                 u.checked = false;
147         }
148
149 }
150
151 function updateVisibility()
152 {
153         if($('#adv_interval').is(':checked')) {
154                 $('#job_interval_advanced').parent().parent().show();
155                 $('#job_interval_basic').parent().parent().hide();
156                 $('#LBL_ADV_OPTIONS').show();
157         } else {
158                 $('#job_interval_advanced').parent().parent().hide();
159                 $('#job_interval_basic').parent().parent().show();
160                 $('#LBL_ADV_OPTIONS').hide();
161         }
162 }
163
164 function initScheduler(){
165         if(typeof(adv_interval) != "undefined" && adv_interval){
166                 $('#adv_interval').prop("checked", true);
167         }
168 }
169
170 $('#EditView_tabs').ready(function() {
171         initScheduler();
172         updateVisibility();
173 });
174 $('#adv_interval').ready(function() {$('#adv_interval').click(updateVisibility); });