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>
</dt>
<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>
</dl>
</div>
@ -203,7 +203,6 @@
<!-- 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/jquery-1.6.1.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
App.Empty = {};
App.Empty.USER = {'CONTACT':'', 'PASSWORD':'','LOGIN_NAME':'','LNAME':'', 'FNAME':'','NS1':'','NS2':'','NS3':'','NS4':'','NS5':'','NS6':'','NS7':'','NS8':''};

View file

@ -93,13 +93,11 @@ App.Actions.edit = function(evt) {
elm = elm.hasClass('row') ? elm : elm.parents('.row');
var options = elm.find('.source').val();
fb.warn(elm);
fb.warn(options);
var build_method = App.Env.getWorldName() + '_form';
var tpl = App.HTML.Build[build_method](options);
elm.replaceWith(tpl);
//App.Pages[App.Env.world].edit(elm);
App.Helpers.disbleNotEditable();
//App.Helpers.updateScreen();
}

View file

@ -202,10 +202,14 @@ App.Helpers.getFormValuesFromElement = function(ref)
App.Helpers.updateScreen = function()
{
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){
// $(o).selectbox();
//});
}
}
App.Helpers.alert = function(msg)
{
@ -287,3 +291,21 @@ App.Helpers.getBackendUrl = function()
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

@ -200,7 +200,7 @@ App.HTML.Build.user_entry = function(o, key)
var ns = [];
var ns_full = [];
fb.info(o);
$([1,2,3,4,5,6,7,8]).each(function(i, index)
{
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)
{
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');
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.Build.user_selects(tpl, options);
if (options.REPORTS_ENABLED == 'yes') {
tpl.set(':CHECKED', 'checked="checked"');
}
else {
tpl.set(':CHECKED', '');
}
return tpl.finalize();
}
@ -301,18 +308,18 @@ App.HTML.Build.web_domain_form = function(options, id)
tpl.set(':id', id || '');
options = App.Helpers.evalJSON(options) || {};
if (App.Helpers.isEmpty(options)) {
tpl.set(':title', 'New user');
tpl.set(':title', 'New WEB domain');
tpl.set(':save_button', 'ADD');
}
else {
tpl.set(':title', 'Edit user');
tpl.set(':title', 'Edit WEB domain');
tpl.set(':save_button', 'SAVE');
}
options = !App.Helpers.isEmpty(options) ? options : App.Empty.WEB_DOMAIN;
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();
}
@ -560,7 +567,27 @@ App.HTML.Build.dns_selects = function(tpl, options)
tpl.set(':TPL_DEFAULT_VALUE', options.TPL || App.Helpers.getFirstKey(obj));
}
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;

View file

@ -69,7 +69,7 @@ App.Model.add = function(values, source_json)
spell: $.toJSON(values)
}, function(reply){
if(!reply.result) {
App.Helpers.Warn('Changes were not applied');
App.Helpers.Warn('Changes were not applied ' + App.Helpers.toJSON(reply.errors) );
}
else {
/*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);
elm.replaceWith(tpl);
}

View file

@ -43,7 +43,7 @@ App.Templates.html = {
},
dns: {
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="target" class="target" value=\'\'>\
<div class="entry-header">~!:title~!</div>\
@ -167,7 +167,7 @@ App.Templates.html = {
},
ip: {
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="target" class="target" value=\'~!:target~!\'>\
<div class="entry-header">~!:title~!</div>\
@ -328,7 +328,7 @@ App.Templates.html = {
</div>\
<div class="form-row cc">\
<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 class="form-row cc">\
<label for="#" class="field-label">Firstname:</label>\
@ -493,7 +493,7 @@ App.Templates.html = {
</div>']
},
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="target" name="target" value="" />\
<div class="entry-header">~!:title~!</div>\
@ -699,11 +699,11 @@ App.Templates.html = {
</span>\
</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="target" class="target" value=\'\'>\
<div class="entry-header">~!:title~!</div>\
<div class="form-error">\
<div class="form-error hidden">\
</div>\
<div class="form-row cc">\
<label for="#" class="field-label">db type:</label>\
@ -785,7 +785,7 @@ App.Templates.html = {
</div>']
},
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="target" class="target" value=\'\'>\
<div class="entry-header">~!:title~!</div>\
@ -798,31 +798,31 @@ App.Templates.html = {
<div class="field-box cron-minute-box">\
<label for="#" class="field-label ">minute:<br>(0&mdash;59)</label>\
<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 class="field-box cron-hour-box">\
<label for="#" class="field-label">hour:<br>(0&mdash;23)</label>\
<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 class="field-box cron-day-box">\
<label for="#" class="field-label">day of Month:<br>(1&mdash;31)</label>\
<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 class="field-box cron-month-box">\
<label for="#" class="field-label">Month:<br>(1&mdash;12)(Jan&mdash;Dec)</label>\
<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 class="field-box cron-week-box">\
<label for="#" class="field-label">day of Week:<br>(1&mdash;7)(Sun&mdash;Sat)</label>\
<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>\

View file

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