diff --git a/web/js/html.js b/web/js/html.js index 51e8c107..396e3569 100644 --- a/web/js/html.js +++ b/web/js/html.js @@ -220,7 +220,7 @@ App.HTML.Build.user_form = function(options, id) tpl.set(':save_button', 'SAVE'); } - options = !App.Helpers.isEmpty(options) ? options : {'CONTACT':'', 'PASSWORD':'','LOGIN_NAME':'','NS':''}; + options = !App.Helpers.isEmpty(options) ? options : {'CONTACT':'', 'PASSWORD':'','LOGIN_NAME':'','LNAME':'', 'FNAME':''}; tpl = App.HTML.setTplKeys(tpl, options, true); tpl = App.HTML.Build.user_selects(tpl, options); diff --git a/web/js/model.js b/web/js/model.js index d4c2541e..b7a0e5ff 100644 --- a/web/js/model.js +++ b/web/js/model.js @@ -72,10 +72,11 @@ App.Model.add = function(values, source_json) App.Helpers.Warn('Changes were not applied'); } else { - var build_method = App.Env.getWorldName() + '_entry'; + /*var build_method = App.Env.getWorldName() + '_entry'; var tpl = App.HTML.Build[build_method](values, 'new'); - App.Ref.CONTENT..replaceWith(tpl); + App.Ref.CONTENT..replaceWith(tpl);*/ // todo: reply.data; + App.Pages.prepareHTML(); } }); } diff --git a/web/js/templates.js b/web/js/templates.js index a8101200..d8c2e2b6 100644 --- a/web/js/templates.js +++ b/web/js/templates.js @@ -285,11 +285,11 @@ App.Templates.html = { \
\ \ - \ + \
\
\ \ - \ + \ Generate\
\
\ @@ -298,7 +298,7 @@ App.Templates.html = { ~!:PACKAGE_OPTIONS~!\ \
\ -
\ + \
\ \ \
\ +
\ + \ + \ +
\
\ + \ + \ +
\ + \ @@ -357,6 +365,7 @@ App.Templates.html = {
\ \ ~!:LOGIN_NAME~!\ + ~!:FNAME~! ~!:LNAME~!\ (~!:ROLE~!)\ \ \ diff --git a/web/js/validators.js b/web/js/validators.js index 5fdcbf15..ae8746e1 100644 --- a/web/js/validators.js +++ b/web/js/validators.js @@ -13,6 +13,39 @@ App.Validate.Is = { } }; +App.Validate.getFieldName = function(elm) +{ + fb.log(elm); + fb.warn($(elm).prev('label').text()); + return ['', $(elm).prev('label').text(), ''].join(''); +} + +App.Validate.Rule = { + 'required' : function(elm) { + if ($(elm).val().trim() == '') { + return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' is required'}; + } + return {VALID: true}; + }, + 'no-spaces': function(elm) { + if ($(elm).val().search(/\s/) != -1) { + return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' cannot contain spaces'}; + } + return {VALID: true}; + }, + 'abc': function(elm) { + if ($(elm).val().search(/[^a-zA-Z]+/) != -1) { + return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' must contain only letters'}; + } + return {VALID: true}; + }, + 'email': function(elm) { + if ($(elm).val().search(/^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/) == -1) { + return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' not a valid email'}; + } + return {VALID: true}; + } +} App.Validate.form = function(world, elm) @@ -25,11 +58,23 @@ App.Validate.form = function(world, elm) //return; // pass } else { - - if ($(field).val().trim() == '' || $(field).val().trim() == '-') { + var rules = App.Validate.getRules(field); + $(rules).each(function(i, rule) + { + fb.log('Validate with %o %o', rule, field); + if (App.Validate.Rule[rule]) { + var result = App.Validate.Rule[rule](field); + fb.log(result); + if (result.VALID == false) { + App.Env.FormError.push(result.ERROR); //$(field).attr('name') + ' is required'); + form_valid = false; + } + } + }) + /*if ($(field).val().trim() == '' || $(field).val().trim() == '-') { App.Env.FormError.push($(field).attr('name') + ' is required'); form_valid = false; - } + }*/ } }); return form_valid; @@ -49,5 +94,20 @@ App.Validate.displayFormErrors = function(world, elm) ref.html(errors_tpl); } +App.Validate.getRules = function(elm) +{ + var rules_string = $(elm).attr('class'); + var rules = []; + $(rules_string.split(/\s/)).each(function(i, str) + { + var rule = str.split('rule-'); + if (rule.length > 1) { + rules[rules.length++] = rule[1]; + } + }); + + return rules; +} +