From 257423147edf4a8bcd356e0858bc8a01ccf56176 Mon Sep 17 00:00:00 2001 From: Malishev Dmitry Date: Fri, 9 Sep 2011 20:29:10 +0300 Subject: [PATCH] Javascript update set --- web/index.html | 5 ++--- web/js/_settings.js | 7 +++++++ web/js/actions.js | 8 +++----- web/js/helpers.js | 24 +++++++++++++++++++++++- web/js/html.js | 41 ++++++++++++++++++++++++++++++++++------- web/js/model.js | 2 +- web/js/pages.js | 1 + web/js/templates.js | 24 ++++++++++++------------ web/js/validators.js | 30 +++++++++++------------------- 9 files changed, 94 insertions(+), 48 deletions(-) diff --git a/web/index.html b/web/index.html index 857c81007..479163e44 100644 --- a/web/index.html +++ b/web/index.html @@ -124,7 +124,7 @@  
- 0 total records + 0 total records
@@ -202,8 +202,7 @@ - - + diff --git a/web/js/_settings.js b/web/js/_settings.js index 802db2b06..0fa6df8a4 100644 --- a/web/js/_settings.js +++ b/web/js/_settings.js @@ -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':''}; diff --git a/web/js/actions.js b/web/js/actions.js index e02bebea2..c5fee8776 100644 --- a/web/js/actions.js +++ b/web/js/actions.js @@ -84,7 +84,7 @@ App.Actions.save_form = function(evt) { if(App.Validate.form(values, $('#'+elm_id))) { App.Model.update(values, source, elm); } - } + } } // do_action_edit @@ -92,14 +92,12 @@ App.Actions.edit = function(evt) { var elm = $(evt.target); elm = elm.hasClass('row') ? elm : elm.parents('.row'); - var options = elm.find('.source').val(); - fb.warn(elm); - fb.warn(options); + var options = elm.find('.source').val(); 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(); } diff --git a/web/js/helpers.js b/web/js/helpers.js index 547c583dc..7e1c4e563 100644 --- a/web/js/helpers.js +++ b/web/js/helpers.js @@ -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); + } + }); + } + }); +} diff --git a/web/js/html.js b/web/js/html.js index 158244384..12f152dc1 100644 --- a/web/js/html.js +++ b/web/js/html.js @@ -197,10 +197,10 @@ App.HTML.Build.user_entry = function(o, key) var sub_tpl = App.Templates.get('SUSPENDED_TPL_NOT_SUSPENDED', 'general'); }*/ tpl.set(':SUSPENDED_TPL', '');//sub_tpl.finalize()); - + 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; diff --git a/web/js/model.js b/web/js/model.js index c97828cec..8c4d54d14 100644 --- a/web/js/model.js +++ b/web/js/model.js @@ -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'; diff --git a/web/js/pages.js b/web/js/pages.js index 631f36063..f400d6aeb 100644 --- a/web/js/pages.js +++ b/web/js/pages.js @@ -48,3 +48,4 @@ App.Pages.DNS.edit = function(elm) { var tpl = App.HTML.Build.dns_form(options); elm.replaceWith(tpl); } + diff --git a/web/js/templates.js b/web/js/templates.js index 831b60a51..fd32a31a7 100644 --- a/web/js/templates.js +++ b/web/js/templates.js @@ -43,7 +43,7 @@ App.Templates.html = { }, dns: { FORM: [ - '
\ + '
\ \ \
~!:title~!
\ @@ -167,7 +167,7 @@ App.Templates.html = { }, ip: { FORM: ['\ -
\ +
\ \ \
~!:title~!
\ @@ -328,7 +328,7 @@ App.Templates.html = {
\
\ \ - \ + \
\
\ \ @@ -493,7 +493,7 @@ App.Templates.html = {
'] }, web_domain: { - FORM: ['
\ + FORM: ['
\ \ \
~!:title~!
\ @@ -699,11 +699,11 @@ App.Templates.html = { \
'], ENTRIES_WRAPPER: ['
~!:content~!
'], - FORM: ['
\ + FORM: ['
\ \ \
~!:title~!
\ -
\ + \
\ \ @@ -785,7 +785,7 @@ App.Templates.html = {
'] }, cron: { - FORM: ['
\ + FORM: ['
\ \ \
~!:title~!
\ @@ -798,31 +798,31 @@ App.Templates.html = {
\ \
\ - \ + \
\
\
\ \
\ - \ + \
\
\
\ \
\ - \ + \
\
\
\ \
\ - \ + \
\
\
\ \
\ - \ + \
\
\
\ diff --git a/web/js/validators.js b/web/js/validators.js index 8bf626a86..82ebd28cc 100644 --- a/web/js/validators.js +++ b/web/js/validators.js @@ -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};