Javascript update set

This commit is contained in:
Malishev Dmitry 2011-09-09 20:29:10 +03:00
parent 0b9711d7c9
commit 257423147e
9 changed files with 94 additions and 48 deletions

View file

@ -124,7 +124,7 @@
<i class="add-entry do_action_new_entry">&nbsp;</i> <i class="add-entry do_action_new_entry">&nbsp;</i>
</dt> </dt>
<dd class="section-contains"> <dd class="section-contains">
<span class="def total_dns_records">0 total records</span> <span class="def"><span class="num-total">0</span> total records</span>
</dd> </dd>
</dl> </dl>
</div> </div>
@ -202,8 +202,7 @@
</div> </div>
<!-- script type="text/javascript" src="js/lib/jquery-1.4.4.min.js"></script -->
<script type="text/javascript" src="js/lib/cookie.js"></script> <script type="text/javascript" src="js/lib/cookie.js"></script>
<script type="text/javascript" src="js/lib/jquery-1.6.1.js"></script> <script type="text/javascript" src="js/lib/jquery-1.6.1.js"></script>
<script type="text/javascript" src="js/lib/jquery-ui-1.8.13.custom.min.js"></script> <script type="text/javascript" src="js/lib/jquery-ui-1.8.13.custom.min.js"></script>

View file

@ -37,6 +37,13 @@ App.Messages.get = function(key, plural) {
} }
} }
// Imutable
App.Settings.Imutable = {};
App.Settings.Imutable.USER = ['LOGIN_NAME'];
App.Settings.Imutable.DB = ['DB', 'TYPE', 'USER'];
App.Settings.Imutable.DNS = ['DNS_DOMAIN'];
// Empty // Empty
App.Empty = {}; App.Empty = {};
App.Empty.USER = {'CONTACT':'', 'PASSWORD':'','LOGIN_NAME':'','LNAME':'', 'FNAME':'','NS1':'','NS2':'','NS3':'','NS4':'','NS5':'','NS6':'','NS7':'','NS8':''}; App.Empty.USER = {'CONTACT':'', 'PASSWORD':'','LOGIN_NAME':'','LNAME':'', 'FNAME':'','NS1':'','NS2':'','NS3':'','NS4':'','NS5':'','NS6':'','NS7':'','NS8':''};

View file

@ -84,7 +84,7 @@ App.Actions.save_form = function(evt) {
if(App.Validate.form(values, $('#'+elm_id))) { if(App.Validate.form(values, $('#'+elm_id))) {
App.Model.update(values, source, elm); App.Model.update(values, source, elm);
} }
} }
} }
// do_action_edit // do_action_edit
@ -92,14 +92,12 @@ App.Actions.edit = function(evt) {
var elm = $(evt.target); var elm = $(evt.target);
elm = elm.hasClass('row') ? elm : elm.parents('.row'); elm = elm.hasClass('row') ? elm : elm.parents('.row');
var options = elm.find('.source').val(); var options = elm.find('.source').val();
fb.warn(elm);
fb.warn(options);
var build_method = App.Env.getWorldName() + '_form'; var build_method = App.Env.getWorldName() + '_form';
var tpl = App.HTML.Build[build_method](options); var tpl = App.HTML.Build[build_method](options);
elm.replaceWith(tpl); elm.replaceWith(tpl);
//App.Pages[App.Env.world].edit(elm); App.Helpers.disbleNotEditable();
//App.Helpers.updateScreen(); //App.Helpers.updateScreen();
} }

View file

@ -202,10 +202,14 @@ App.Helpers.getFormValuesFromElement = function(ref)
App.Helpers.updateScreen = function() App.Helpers.updateScreen = function()
{ {
Custom.init(); Custom.init();
App.Ajax.request('MAIN.getInitial', {}, function(reply){
App.Env.initialParams = reply.data;
App.Helpers.updateInitial();
});
//$(document.body).find('select').each(function(i, o){ //$(document.body).find('select').each(function(i, o){
// $(o).selectbox(); // $(o).selectbox();
//}); //});
} }
App.Helpers.alert = function(msg) App.Helpers.alert = function(msg)
{ {
@ -287,3 +291,21 @@ App.Helpers.getBackendUrl = function()
return url_parts.join('/'); return url_parts.join('/');
} }
App.Helpers.disbleNotEditable = function()
{
if ('undefined' == typeof App.Settings.Imutable[App.Env.world]) {
return false;
}
$('.form').each(function(i, form)
{
if ($(form).attr('id') == '') {
$('input, select, textarea', form).each(function(i, elm) {
if ($.inArray($(elm).attr('name'), App.Settings.Imutable[App.Env.world]) != -1) {
$(elm).attr('disabled', true);
}
});
}
});
}

View file

@ -197,10 +197,10 @@ App.HTML.Build.user_entry = function(o, key)
var sub_tpl = App.Templates.get('SUSPENDED_TPL_NOT_SUSPENDED', 'general'); var sub_tpl = App.Templates.get('SUSPENDED_TPL_NOT_SUSPENDED', 'general');
}*/ }*/
tpl.set(':SUSPENDED_TPL', '');//sub_tpl.finalize()); tpl.set(':SUSPENDED_TPL', '');//sub_tpl.finalize());
var ns = []; var ns = [];
var ns_full = []; var ns_full = [];
fb.info(o);
$([1,2,3,4,5,6,7,8]).each(function(i, index) $([1,2,3,4,5,6,7,8]).each(function(i, index)
{ {
if (o['NS'+index].trim() != '') { if (o['NS'+index].trim() != '') {
@ -233,7 +233,7 @@ App.HTML.Build.user_entry = function(o, key)
App.HTML.Build.user_form = function(options, id) App.HTML.Build.user_form = function(options, id)
{ {
if('undefined' == typeof App.Env.initialParams) { if('undefined' == typeof App.Env.initialParams) {
return alert('PLease wait a bit. Some background processes are not yet executed. Thank you for patience.'); return alert('Please wait a bit. Some background processes are not yet executed. Thank you for patience.');
} }
var tpl = App.Templates.get('FORM', 'user'); var tpl = App.Templates.get('FORM', 'user');
tpl.set(':source', options); tpl.set(':source', options);
@ -268,6 +268,13 @@ App.HTML.Build.user_form = function(options, id)
tpl = App.HTML.setTplKeys(tpl, options, true); tpl = App.HTML.setTplKeys(tpl, options, true);
tpl = App.HTML.Build.user_selects(tpl, options); tpl = App.HTML.Build.user_selects(tpl, options);
if (options.REPORTS_ENABLED == 'yes') {
tpl.set(':CHECKED', 'checked="checked"');
}
else {
tpl.set(':CHECKED', '');
}
return tpl.finalize(); return tpl.finalize();
} }
@ -301,18 +308,18 @@ App.HTML.Build.web_domain_form = function(options, id)
tpl.set(':id', id || ''); tpl.set(':id', id || '');
options = App.Helpers.evalJSON(options) || {}; options = App.Helpers.evalJSON(options) || {};
if (App.Helpers.isEmpty(options)) { if (App.Helpers.isEmpty(options)) {
tpl.set(':title', 'New user'); tpl.set(':title', 'New WEB domain');
tpl.set(':save_button', 'ADD'); tpl.set(':save_button', 'ADD');
} }
else { else {
tpl.set(':title', 'Edit user'); tpl.set(':title', 'Edit WEB domain');
tpl.set(':save_button', 'SAVE'); tpl.set(':save_button', 'SAVE');
} }
options = !App.Helpers.isEmpty(options) ? options : App.Empty.WEB_DOMAIN; options = !App.Helpers.isEmpty(options) ? options : App.Empty.WEB_DOMAIN;
tpl = App.HTML.setTplKeys(tpl, options, true); tpl = App.HTML.setTplKeys(tpl, options, true);
tpl = App.HTML.Build.user_selects(tpl, options); tpl = App.HTML.Build.web_domain_selects(tpl, options);
return tpl.finalize(); return tpl.finalize();
} }
@ -560,7 +567,27 @@ App.HTML.Build.dns_selects = function(tpl, options)
tpl.set(':TPL_DEFAULT_VALUE', options.TPL || App.Helpers.getFirstKey(obj)); tpl.set(':TPL_DEFAULT_VALUE', options.TPL || App.Helpers.getFirstKey(obj));
} }
catch (e) { catch (e) {
return ''; return tpl;
}
return tpl;
}
App.HTML.Build.web_domain_selects = function(tpl, options)
{
try {
// IP
var obj = App.Env.initialParams.WEB_DOMAIN.IP;
var opts = App.HTML.Build.options(obj, options.IP);
tpl.set(':IP_OPTIONS', opts);
// TPL
var obj = App.Env.initialParams.WEB_DOMAIN.TPL;
var opts = App.HTML.Build.options(obj, options.TPL);
tpl.set(':TPL_OPTIONS', opts);
}
catch (e) {
return tpl;
} }
return tpl; return tpl;

View file

@ -69,7 +69,7 @@ App.Model.add = function(values, source_json)
spell: $.toJSON(values) spell: $.toJSON(values)
}, function(reply){ }, function(reply){
if(!reply.result) { if(!reply.result) {
App.Helpers.Warn('Changes were not applied'); App.Helpers.Warn('Changes were not applied ' + App.Helpers.toJSON(reply.errors) );
} }
else { else {
/*var build_method = App.Env.getWorldName() + '_entry'; /*var build_method = App.Env.getWorldName() + '_entry';

View file

@ -48,3 +48,4 @@ App.Pages.DNS.edit = function(elm) {
var tpl = App.HTML.Build.dns_form(options); var tpl = App.HTML.Build.dns_form(options);
elm.replaceWith(tpl); elm.replaceWith(tpl);
} }

View file

@ -43,7 +43,7 @@ App.Templates.html = {
}, },
dns: { dns: {
FORM: [ FORM: [
'<div style="margin-top: 25px;" class="b-new-entry b-new-entry_dns" id="~!:id~!">\ '<div style="margin-top: 25px;" class="b-new-entry b-new-entry_dns form" id="~!:id~!">\
<input type="hidden" name="source" class="source" value=~!:source~!>\ <input type="hidden" name="source" class="source" value=~!:source~!>\
<input type="hidden" name="target" class="target" value=\'\'>\ <input type="hidden" name="target" class="target" value=\'\'>\
<div class="entry-header">~!:title~!</div>\ <div class="entry-header">~!:title~!</div>\
@ -167,7 +167,7 @@ App.Templates.html = {
}, },
ip: { ip: {
FORM: ['\ FORM: ['\
<div class="b-new-entry b-new-entry_ip" id="~!:id~!">\ <div class="b-new-entry b-new-entry_ip form" id="~!:id~!">\
<input type="hidden" name="source" class="source" value=\'~!:source~!\'>\ <input type="hidden" name="source" class="source" value=\'~!:source~!\'>\
<input type="hidden" name="target" class="target" value=\'~!:target~!\'>\ <input type="hidden" name="target" class="target" value=\'~!:target~!\'>\
<div class="entry-header">~!:title~!</div>\ <div class="entry-header">~!:title~!</div>\
@ -328,7 +328,7 @@ App.Templates.html = {
</div>\ </div>\
<div class="form-row cc">\ <div class="form-row cc">\
<label for="#" class="field-label">reports:</label>\ <label for="#" class="field-label">reports:</label>\
<input type="checkbox" name="REPORTS_ENABLED" class="not-styled" value="~!:REPORTS_ENABLED~!">\ <input type="checkbox" name="REPORTS_ENABLED" ~!:CHECKED~! class="not-styled" value="~!:REPORTS_ENABLED~!">\
</div>\ </div>\
<div class="form-row cc">\ <div class="form-row cc">\
<label for="#" class="field-label">Firstname:</label>\ <label for="#" class="field-label">Firstname:</label>\
@ -493,7 +493,7 @@ App.Templates.html = {
</div>'] </div>']
}, },
web_domain: { web_domain: {
FORM: ['<div id="~!:id~!" class="b-new-entry b-new-entry_domain">\ FORM: ['<div id="~!:id~!" class="b-new-entry b-new-entry_domain form">\
<input type="hidden" class="source" name="source" value=\'~!:source~!\' />\ <input type="hidden" class="source" name="source" value=\'~!:source~!\' />\
<input type="hidden" class="target" name="target" value="" />\ <input type="hidden" class="target" name="target" value="" />\
<div class="entry-header">~!:title~!</div>\ <div class="entry-header">~!:title~!</div>\
@ -699,11 +699,11 @@ App.Templates.html = {
</span>\ </span>\
</div>'], </div>'],
ENTRIES_WRAPPER: ['<div class="db-list">~!:content~!</div>'], ENTRIES_WRAPPER: ['<div class="db-list">~!:content~!</div>'],
FORM: ['<div id="~!:id~!" class="b-new-entry b-new-entry_db">\ FORM: ['<div id="~!:id~!" class="b-new-entry b-new-entry_db form">\
<input type="hidden" name="source" class="source" value=\'~!:source~!\'>\ <input type="hidden" name="source" class="source" value=\'~!:source~!\'>\
<input type="hidden" name="target" class="target" value=\'\'>\ <input type="hidden" name="target" class="target" value=\'\'>\
<div class="entry-header">~!:title~!</div>\ <div class="entry-header">~!:title~!</div>\
<div class="form-error">\ <div class="form-error hidden">\
</div>\ </div>\
<div class="form-row cc">\ <div class="form-row cc">\
<label for="#" class="field-label">db type:</label>\ <label for="#" class="field-label">db type:</label>\
@ -785,7 +785,7 @@ App.Templates.html = {
</div>'] </div>']
}, },
cron: { cron: {
FORM: ['<div class="b-new-entry b-new-entry_cron" id="~!:id~!" >\ FORM: ['<div class="b-new-entry b-new-entry_cron form" id="~!:id~!" >\
<input type="hidden" name="source" class="source" value=\'~!:source~!\'>\ <input type="hidden" name="source" class="source" value=\'~!:source~!\'>\
<input type="hidden" name="target" class="target" value=\'\'>\ <input type="hidden" name="target" class="target" value=\'\'>\
<div class="entry-header">~!:title~!</div>\ <div class="entry-header">~!:title~!</div>\
@ -798,31 +798,31 @@ App.Templates.html = {
<div class="field-box cron-minute-box">\ <div class="field-box cron-minute-box">\
<label for="#" class="field-label ">minute:<br>(0&mdash;59)</label>\ <label for="#" class="field-label ">minute:<br>(0&mdash;59)</label>\
<div class="field-box-inner cc">\ <div class="field-box-inner cc">\
<input type="text" value="~!:MIN~!" name="MIN" class="text-field rule-required rule-minute">\ <input type="text" value="~!:MIN~!" name="MIN" class="text-field rule-required rule-cronminute">\
</div>\ </div>\
</div>\ </div>\
<div class="field-box cron-hour-box">\ <div class="field-box cron-hour-box">\
<label for="#" class="field-label">hour:<br>(0&mdash;23)</label>\ <label for="#" class="field-label">hour:<br>(0&mdash;23)</label>\
<div class="field-box-inner cc">\ <div class="field-box-inner cc">\
<input type="text" value="~!:HOUR~!" name="HOUR" class="text-field rule-required rule-hour">\ <input type="text" value="~!:HOUR~!" name="HOUR" class="text-field rule-required rule-cronhour">\
</div>\ </div>\
</div>\ </div>\
<div class="field-box cron-day-box">\ <div class="field-box cron-day-box">\
<label for="#" class="field-label">day of Month:<br>(1&mdash;31)</label>\ <label for="#" class="field-label">day of Month:<br>(1&mdash;31)</label>\
<div class="field-box-inner cc">\ <div class="field-box-inner cc">\
<input type="text" value="~!:DAY~!" name="DAY" class="text-field rule-required rule-day">\ <input type="text" value="~!:DAY~!" name="DAY" class="text-field rule-required rule-cronday">\
</div>\ </div>\
</div>\ </div>\
<div class="field-box cron-month-box">\ <div class="field-box cron-month-box">\
<label for="#" class="field-label">Month:<br>(1&mdash;12)(Jan&mdash;Dec)</label>\ <label for="#" class="field-label">Month:<br>(1&mdash;12)(Jan&mdash;Dec)</label>\
<div class="field-box-inner cc">\ <div class="field-box-inner cc">\
<input type="text" value="~!:MONTH~!" name="MONTH" class="text-field rule-required rule-month">\ <input type="text" value="~!:MONTH~!" name="MONTH" class="text-field rule-required rule-cronmonth">\
</div>\ </div>\
</div>\ </div>\
<div class="field-box cron-week-box">\ <div class="field-box cron-week-box">\
<label for="#" class="field-label">day of Week:<br>(1&mdash;7)(Sun&mdash;Sat)</label>\ <label for="#" class="field-label">day of Week:<br>(1&mdash;7)(Sun&mdash;Sat)</label>\
<div class="field-box-inner cc">\ <div class="field-box-inner cc">\
<input type="text" value="~!:WDAY~!" name="WDAY" class="text-field rule-required rule-wday">\ <input type="text" value="~!:WDAY~!" name="WDAY" class="text-field rule-required rule-cronwday">\
</div>\ </div>\
</div>\ </div>\
</div>\ </div>\

View file

@ -79,52 +79,44 @@ App.Validate.Rule = {
} }
return {VALID: true}; return {VALID: true};
}, },
'minute': function(elm) { 'cronminute': function(elm) {
if ($(elm).val() == '*') { if ($(elm).val().trim() != '' && $(elm).val().search(/[^0-9\/\*-,]+/) != -1) {
return {VALID: true};
}
var minute = parseInt($(elm).val(), 10);
if (minute > 60 || minute < 0) {
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' wrong minute value'}; return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' wrong minute value'};
} }
return {VALID: true}; return {VALID: true};
}, },
'hour': function(elm) { 'cronhour': function(elm) {
if ($(elm).val() == '*') { if ($(elm).val() == '*') {
return {VALID: true}; return {VALID: true};
} }
var hour = parseInt($(elm).val(), 10); if ($(elm).val().trim() != '' && $(elm).val().search(/[^0-9\/\*-,]+/) != -1) {
if (hour > 60 || hour < 0) {
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' wrong hour value'}; return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' wrong hour value'};
} }
return {VALID: true}; return {VALID: true};
}, },
'wday': function(elm) { 'cronwday': function(elm) {
if ($(elm).val() == '*') { if ($(elm).val() == '*') {
return {VALID: true}; return {VALID: true};
} }
var wday = parseInt($(elm).val(), 10); if ($(elm).val().trim() != '' && $(elm).val().search(/[^123456\/\*-,]+/) != -1) {
if (wday > 7 || wday < 1) {
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' wrong week day value'}; return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' wrong week day value'};
} }
return {VALID: true}; return {VALID: true};
}, },
'month': function(elm) { 'cronmonth': function(elm) {
if ($(elm).val() == '*') { if ($(elm).val() == '*') {
return {VALID: true}; return {VALID: true};
} }
var month = parseInt($(elm).val(), 10); if ($(elm).val().trim() != '' && $(elm).val().search(/[^0-9\/\*-,]+/) != -1) {
if (month > 1 || month < 12) {
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' wrong month value'}; return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' wrong month value'};
} }
return {VALID: true}; return {VALID: true};
}, },
'day': function(elm) { 'cronday': function(elm) {
if ($(elm).val() == '*') { if ($(elm).val() == '*') {
return {VALID: true}; return {VALID: true};
} }
var day = parseInt($(elm).val(), 10); if ($(elm).val().trim() != '' && $(elm).val().search(/[^0-9\/\*-,]+/) != -1) {
if (day > 31 || day < 1) {
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' wrong day value'}; return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' wrong day value'};
} }
return {VALID: true}; return {VALID: true};