From 0f2c093148d2e7999490a0bc88abd7eac3b4d52b Mon Sep 17 00:00:00 2001 From: Malishev Dmitry Date: Fri, 2 Sep 2011 17:12:55 +0300 Subject: [PATCH 1/9] ~ --- web/LICENSE.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/LICENSE.txt b/web/LICENSE.txt index c77cede3..fc62e9c1 100644 --- a/web/LICENSE.txt +++ b/web/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright (c) 2005-2010, http://vestacp.com +Copyright (c) 2005-2010, http://www.vestacp.com All rights reserved. Redistribution and use in source and binary forms, with or without modification, From f651c68a6a83c8cd826b6942e382d1956e48a2e3 Mon Sep 17 00:00:00 2001 From: Malishev Dmitry Date: Fri, 2 Sep 2011 21:38:27 +0300 Subject: [PATCH 2/9] Save active tab in cookie in order to restore after page refresh --- web/dispatch.php | 2 +- web/index.html | 1 + web/js/__init__.js | 16 +++++- web/js/app.js | 15 ++---- web/js/helpers.js | 23 +++++++++ web/js/pages.js | 4 ++ web/vesta/api/AjaxHandler.php | 5 ++ web/vesta/api/USER.class.php | 97 ++++++++++++++++------------------- web/vesta/app.init.php | 1 + 9 files changed, 99 insertions(+), 65 deletions(-) diff --git a/web/dispatch.php b/web/dispatch.php index e6a31ceb..6733f2d7 100644 --- a/web/dispatch.php +++ b/web/dispatch.php @@ -1,6 +1,6 @@ diff --git a/web/index.html b/web/index.html index f32a88a6..760a2305 100644 --- a/web/index.html +++ b/web/index.html @@ -204,6 +204,7 @@ + diff --git a/web/js/__init__.js b/web/js/__init__.js index 655eee05..c8bbeb61 100644 --- a/web/js/__init__.js +++ b/web/js/__init__.js @@ -1,7 +1,21 @@ $(document).ready(function(){ try{ App.Utils.detectBrowser(); - App.Env.world = 'CRON'; + + if ('undefined' != typeof App.Tmp.loadTAB) { + App.Env.world = App.Tmp.loadTAB; + } + + if ('undefined' == typeof App.Tmp.loadTAB && cookieEnabled()) { + var tab = getCookie('tab'); + if (null != tab && $.inArray(tab, App.Constants.TABS)) { + App.Env.world = tab; + } + else { + App.Env.world = App.Constants.TABS[0]; + } + } + App.Pages.init(); App.Ref.init(); diff --git a/web/js/app.js b/web/js/app.js index aa7ac706..373e403f 100644 --- a/web/js/app.js +++ b/web/js/app.js @@ -78,7 +78,9 @@ var App = { Core: {}, Bash: {}, Console: {}, - Constants: {}, + Constants: { + TABS: ['USER','WEB_DOMAIN','MAIL','DB','DNS','IP','CRON'] + }, Actions: {}, Helpers: {}, Filters: {}, @@ -175,16 +177,7 @@ App.Ajax.request = function(jedi_method, data, callback) { App.Helpers.beforeAjax(jedi_method); $.ajax({ - url: function() { - var url_parts = location.href.replace('#', '').split('/'); - if (url_parts[url_parts.length -1] == 'index.html') { - url_parts[url_parts.length -1] = 'dispatch.php'; - } - else { - url_parts.push('dispatch.php'); - } - return url_parts.join('/'); - }(), + url: App.Helpers.getBackendUrl(), global: false, type: data.request_method || "POST", data: $.extend(data, {'jedi_method': jedi_method}), diff --git a/web/js/helpers.js b/web/js/helpers.js index 00d33379..547c583d 100644 --- a/web/js/helpers.js +++ b/web/js/helpers.js @@ -264,3 +264,26 @@ App.Helpers.closeInnerPopup = function(evt) { $('#inner-popup').remove(); } + +App.Helpers.getBackendUrl = function() +{ + var url_parts = location.href.split('#'); + if (url_parts.length > 1) { + var tab = url_parts[url_parts.length - 1]; + if ($.inArray(tab, App.Constants.TABS) != -1) { + App.Tmp.loadTAB = tab; + } + } + + var url_parts = location.href.split('?', 1); + var url = url_parts[0]; + url_parts = url.split('/'); + if (url_parts[url_parts.length -1] == 'index.html') { + url_parts[url_parts.length -1] = 'dispatch.php'; + } + else { + url_parts.push('dispatch.php'); + } + + return url_parts.join('/'); +} diff --git a/web/js/pages.js b/web/js/pages.js index 63089ff5..631f3606 100644 --- a/web/js/pages.js +++ b/web/js/pages.js @@ -8,6 +8,10 @@ App.Pages.init = function(){ $('.section.active').removeClass('active'); $('#'+App.Env.world).addClass('active'); + + if (cookieEnabled()) { + setCookie('tab', App.Env.world); + } } App.Pages.prepareHTML = function() diff --git a/web/vesta/api/AjaxHandler.php b/web/vesta/api/AjaxHandler.php index 5bbc8899..827b1328 100644 --- a/web/vesta/api/AjaxHandler.php +++ b/web/vesta/api/AjaxHandler.php @@ -24,6 +24,11 @@ class AjaxHandler { { return null == self::$instance ? self::$instance = new self() : self::$instance; } + + public function getLoggedUser() + { + return VestaSession::getInstance()->getUser(); + } /** * Called functions should reply in the following way diff --git a/web/vesta/api/USER.class.php b/web/vesta/api/USER.class.php index 77dac79e..57089160 100644 --- a/web/vesta/api/USER.class.php +++ b/web/vesta/api/USER.class.php @@ -17,7 +17,7 @@ class USER extends AjaxHandler * @param Request $request * @return string - Ajax Reply */ - public function getListExecute($request) + public function getListExecute(Request $request) { $reply = array(); $result = Vesta::execute(Vesta::V_LIST_SYS_USERS, array(Config::get('response_type'))); @@ -34,40 +34,40 @@ class USER extends AjaxHandler $reply[$user] = array( "LOGIN_NAME" => $user, "FULLNAME" => $fullname, // TODO skid - "PACKAGE" => $details['PACKAGE'], - "WEB_DOMAINS" => $details['WEB_DOMAINS'], - "WEB_SSL" => $details['WEB_SSL'], - "WEB_ALIASES" => $details['WEB_ALIASES'], - "DATABASES" => $details['DATABASES'], - "MAIL_DOMAINS" => $details['MAIL_DOMAINS'], - "MAIL_BOXES" => $details['MAIL_BOXES'], - "MAIL_FORWARDERS" => $details['MAIL_FORWARDERS'], - "DNS_DOMAINS" => $details['DNS_DOMAINS'], - "DISK_QUOTA" => $details['DISK_QUOTA'],//$disk_quota, - "BANDWIDTH" => $details['BANDWIDTH'],//$bandwidth, - "NS_LIST" => array($details['NS1'], $details['NS2']), // TODO skid - "SHELL" => $details['"SHELL'], - "BACKUPS" => $details['BACKUPS'], - "WEB_TPL" => $details['WEB_TPL'], - "MAX_CHILDS" => $details['MAX_CHILDS'], - "SUSPENDED" => $details['SUSPENDED'], - "OWNER" => $details['OWNER'], - "ROLE" => $details['ROLE'], - "IP_OWNED" => $details['IP_OWNED'], - "U_CHILDS" => $details['U_CHILDS'], - "U_DISK" => $details['U_DISK'],//$u_disk, - "U_BANDWIDTH" => $details['U_BANDWIDTH'],//$u_bandwidth, - "U_WEB_DOMAINS" => $details['U_WEB_DOMAINS'], - "U_WEB_SSL" => $details['U_WEB_SSL'], - "U_DNS_DOMAINS" => $details['U_DNS_DOMAINS'], - "U_DATABASES" => $details['U_DATABASES'], - "U_MAIL_DOMAINS" => $details['U_MAIL_DOMAINS'], - "CONTACT" => $details['CONTACT'], - "DATE" => $details['DATE'], + "PACKAGE" => $details['PACKAGE'], + "WEB_DOMAINS" => $details['WEB_DOMAINS'], + "WEB_SSL" => $details['WEB_SSL'], + "WEB_ALIASES" => $details['WEB_ALIASES'], + "DATABASES" => $details['DATABASES'], + "MAIL_DOMAINS" => $details['MAIL_DOMAINS'], + "MAIL_BOXES" => $details['MAIL_BOXES'], + "MAIL_FORWARDERS" => $details['MAIL_FORWARDERS'], + "DNS_DOMAINS" => $details['DNS_DOMAINS'], + "DISK_QUOTA" => $details['DISK_QUOTA'],//$disk_quota, + "BANDWIDTH" => $details['BANDWIDTH'],//$bandwidth, + "NS_LIST" => array($details['NS1'], $details['NS2']), // TODO skid + "SHELL" => $details['"SHELL'], + "BACKUPS" => $details['BACKUPS'], + "WEB_TPL" => $details['WEB_TPL'], + "MAX_CHILDS" => $details['MAX_CHILDS'], + "SUSPENDED" => $details['SUSPENDED'], + "OWNER" => $details['OWNER'], + "ROLE" => $details['ROLE'], + "IP_OWNED" => $details['IP_OWNED'], + "U_CHILDS" => $details['U_CHILDS'], + "U_DISK" => $details['U_DISK'],//$u_disk, + "U_BANDWIDTH" => $details['U_BANDWIDTH'],//$u_bandwidth, + "U_WEB_DOMAINS" => $details['U_WEB_DOMAINS'], + "U_WEB_SSL" => $details['U_WEB_SSL'], + "U_DNS_DOMAINS" => $details['U_DNS_DOMAINS'], + "U_DATABASES" => $details['U_DATABASES'], + "U_MAIL_DOMAINS" => $details['U_MAIL_DOMAINS'], + "CONTACT" => $details['CONTACT'], + "DATE" => $details['DATE'], - "U_MAIL_BOXES" => rand(1, 10), // TODO: skid - "U_MAIL_FORWARDERS" => rand(1, 10), // TODO: skid - "REPORTS_ENABLED" => 'enabled' // TODO: skid + "U_MAIL_BOXES" => rand(1, 10), // TODO: skid + "U_MAIL_FORWARDERS" => rand(1, 10), // TODO: skid + "REPORTS_ENABLED" => 'enabled' // TODO: skid ); } @@ -80,26 +80,19 @@ class USER extends AjaxHandler * @param Request $request * @return string - Ajax Reply */ - public function addExecute($_spell = FALSE) + public function addExecute(Request $request) { - $r = new Request(); - if ($_spell) { - $_s = $_spell; - } - else { - $_s = $r->getSpell(); - } - - $_user = 'vesta'; + $spell = $request->getParameter('spell'); + $user = $this->getLoggedUser(); $params = array( - 'USER' => $_s['USER'], - 'PASSWORD' => $_s['PASSWORD'], - 'EMAIL' => $_s['EMAIL'], - 'ROLE' => $_s['ROLE'], - 'OWNER' => $_user, - 'PACKAGE' => $_s['PACKAGE'], - 'NS1' => $_s['NS1'], - 'NS2' => $_s['NS2'] + 'USER' => $spell['USER'], + 'PASSWORD' => $spell['PASSWORD'], + 'EMAIL' => $spell['EMAIL'], + 'ROLE' => $spell['ROLE'], + 'OWNER' => $user['uid'], + 'PACKAGE' => $spell['PACKAGE'], + 'NS1' => $spell['NS1'], + 'NS2' => $spell['NS2'] ); $result = Vesta::execute(Vesta::V_ADD_SYS_USER, $params); diff --git a/web/vesta/app.init.php b/web/vesta/app.init.php index 835d44ca..a4aa2976 100644 --- a/web/vesta/app.init.php +++ b/web/vesta/app.init.php @@ -3,6 +3,7 @@ define('V_ROOT_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR); require_once V_ROOT_DIR . 'config/Config.class.php'; +require_once V_ROOT_DIR . 'core/VestaSession.class.php'; require_once V_ROOT_DIR . 'core/Vesta.class.php'; require_once V_ROOT_DIR . 'core/exceptions/SystemException.class.php'; require_once V_ROOT_DIR . 'core/exceptions/ProtectionException.class.php'; From f65b8c618bb41f38c9525004dcce41b41e3c8c7a Mon Sep 17 00:00:00 2001 From: Malishev Dmitry Date: Fri, 2 Sep 2011 21:39:10 +0300 Subject: [PATCH 3/9] Vesta session class --- web/vesta/core/VestaSession.class.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 web/vesta/core/VestaSession.class.php diff --git a/web/vesta/core/VestaSession.class.php b/web/vesta/core/VestaSession.class.php new file mode 100644 index 00000000..038e01f7 --- /dev/null +++ b/web/vesta/core/VestaSession.class.php @@ -0,0 +1,25 @@ + 'vesta'); + } + +} + +?> From d5457b58d08e7a14e59b9b4b9a8d94e9879a8e65 Mon Sep 17 00:00:00 2001 From: Dima Malishev Date: Fri, 2 Sep 2011 23:15:07 +0300 Subject: [PATCH 4/9] Validation for no-spaces, a-zA-Z, emails added --- web/js/html.js | 2 +- web/js/model.js | 5 ++-- web/js/templates.js | 17 +++++++++--- web/js/validators.js | 66 ++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 80 insertions(+), 10 deletions(-) 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; +} + From ea5a8a2659567e34abc839c7483b136554b80e7b Mon Sep 17 00:00:00 2001 From: Dima Malishev Date: Fri, 2 Sep 2011 23:16:38 +0300 Subject: [PATCH 5/9] added cookie.js --- web/js/lib/cookie.js | 45 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 web/js/lib/cookie.js diff --git a/web/js/lib/cookie.js b/web/js/lib/cookie.js new file mode 100644 index 00000000..0b99f125 --- /dev/null +++ b/web/js/lib/cookie.js @@ -0,0 +1,45 @@ +var today = new Date(); +var expiryyear = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000); +var expirymonth = new Date(today.getTime() + 30 * 24 * 60 * 60 * 1000); +var expiryday = new Date(today.getTime() + 24 * 60 * 60 * 1000); + +function getCookie(name) +{ + var reg= new RegExp("; "+name+";|; "+name+"=([^;]*)"); + var matches=reg.exec('; '+document.cookie+';'); + if (matches) return ((matches[1])?unescape(matches[1]):''); + return null; +} + +function setCookie (name,value,expires,path,domain,secure) +{ + document.cookie = name + "=" + escape (value) + + ((expires) ? "; expires=" + expires.toGMTString() : "") + + ((path) ? "; path=" + path : "") + + ((domain) ? "; domain=" + domain : "") + + ((secure) ? "; secure" : ""); + + return getCookie(name)!=null?true:false; +} + +function deleteCookie (name,path,domain) +{ + if (getCookie(name)!=null) + { + document.cookie = name + "=" + + ((path) ? "; path=" + path : "") + + ((domain) ? "; domain=" + domain : "") + + "; expires=Thu, 01-Jan-1970 00:00:01 GMT"; + } +} + +function cookieEnabled() +{ + testCookieName="_testCookie_"; + if (setCookie(testCookieName,1)) + { + deleteCookie(testCookieName); + return true; + } + else return false; +} \ No newline at end of file From 04c7a8b545bdab1d9d1d9ec1c0df618aef944f8d Mon Sep 17 00:00:00 2001 From: Dima Malishev Date: Sat, 3 Sep 2011 18:20:14 +0300 Subject: [PATCH 6/9] USERS / CRON / IP ready. DNS (partly). JS form validators written. Added functionality --- web/js/_settings.js | 38 +++---- web/js/actions.js | 97 +++++++++++++++++- web/js/html.js | 67 +++++++++--- web/js/model.js | 6 +- web/js/templates.js | 78 ++++++++------ web/js/validators.js | 125 +++++++++++++++++++---- web/vesta/api/CRON.class.php | 95 ++++++++--------- web/vesta/api/DNS.class.php | 107 ++++++++------------ web/vesta/api/IP.class.php | 52 +++++----- web/vesta/api/MAIN.class.php | 16 +-- web/vesta/api/USER.class.php | 140 ++++++++++++++++---------- web/vesta/app.init.php | 12 +++ web/vesta/core/Request.class.php | 15 ++- web/vesta/core/Vesta.class.php | 9 +- web/vesta/core/utils/error_logger.php | 8 +- 15 files changed, 568 insertions(+), 297 deletions(-) diff --git a/web/js/_settings.js b/web/js/_settings.js index a70b181f..b2e51b28 100644 --- a/web/js/_settings.js +++ b/web/js/_settings.js @@ -8,34 +8,38 @@ App.i18n.getMessage = function(key) } - // Constants -App.Constants.IP_FORM_ID = 'ip-form'; -App.Constants.DNS_FORM_ID = 'dns-form'; -App.Constants.USER_FORM_ID = 'user-form'; -App.Constants.WEB_DOMAIN_FORM_ID = 'web_domain-form'; -App.Constants.DB_FORM_ID = 'db-form'; -App.Constants.CRON_FORM_ID = 'cron-form'; +App.Constants.IP_FORM_ID = 'ip-form'; +App.Constants.DNS_FORM_ID = 'dns-form'; +App.Constants.USER_FORM_ID = 'user-form'; +App.Constants.WEB_DOMAIN_FORM_ID = 'web_domain-form'; +App.Constants.DB_FORM_ID = 'db-form'; +App.Constants.CRON_FORM_ID = 'cron-form'; +App.Constants.IP = 'IP'; +App.Constants.DNS = 'DNS'; +App.Constants.SUSPENDED_YES = 'yes'; +App.Constants.DNS_TEMPLATES = {'default': 'Default'}; -App.Settings.ajax_url = 1; -App.Settings.uri = location.href.replace('index.html', ''); -App.Settings.popup_conf = { 'centered' : true, 'bgcolor' : '#FF0000', 'lightboxSpeed' : 'fast', 'destroyOnClose': true }; +// Settings +App.Settings.USER_VISIBLE_NS = 2; +App.Settings.NS_MIN = 2; +App.Settings.NS_MAX = 8; +App.Settings.ajax_url = 1; +App.Settings.uri = location.href.replace('index.html', ''); +App.Settings.popup_conf = { 'centered' : true, 'bgcolor' : '#FF0000', 'lightboxSpeed' : 'fast', 'destroyOnClose': true }; -App.Constants.SUSPENDED_YES = 'yes'; - -App.Constants.IP = 'IP'; -App.Constants.DNS = 'DNS'; - -App.Constants.DNS_TEMPLATES = {'default': 'Default'}; +// Messages App.Messages.total_dns_records = {single: 'total record', plural: 'total records'}; - App.Messages.get = function(key, plural) { if ('undefined' != typeof App.Messages[key]) { return plural ? App.Messages[key].plural : App.Messages[key].single; } } +// Empty +App.Empty = {}; +App.Empty.USER = {'CONTACT':'', 'PASSWORD':'','LOGIN_NAME':'','LNAME':'', 'FNAME':'','NS1':'','NS2':'','NS3':'','NS4':'','NS5':'','NS6':'','NS7':'','NS8':''}; App.Settings.getMethodName = function(action) { diff --git a/web/js/actions.js b/web/js/actions.js index 299093f3..ef27f0f4 100644 --- a/web/js/actions.js +++ b/web/js/actions.js @@ -103,8 +103,7 @@ App.Actions.save_form = function(evt) { else { // OLD ITEM, UPDATING IT var source = $(elm).find('.source').val(); var values = App.Helpers.getFormValues(elm); - if(App.Validate.form(values, $('#'+elm_id))) { - App.Model.add(values, source); + if(App.Validate.form(values, $('#'+elm_id))) { App.Model.update(values, source, elm); } } @@ -146,12 +145,49 @@ App.Actions.cancel_form = function(evt, params) { App.Actions.suspend = function(evt) { - alert('Suspend?'); + var confirmed = confirm('Suspend?'); + if (!confirmed) { + return ; + } + var elm = $(evt.target); + var row = elm.parents('.row'); + + var options = row.find('.source').val(); + App.Ajax.request(App.Env.world+'.suspend', {spell: options}, function(reply) { + if (reply.result) { + //var tpl = App.Templates.get('SUSPENDED_TPL_SUSPENDED', 'general'); + //$(elm).replaceWith(tpl.finalize()); + App.Pages.prepareHTML(); + App.Helpers.updateScreen(); + } + else { + return App.Helpers.alert('Failed to suspend'); + } + }); } App.Actions.unsuspend = function(evt) { - alert('Unsuspend?'); + var confirmed = confirm('Unsuspend?'); + if (!confirmed) { + return ; + } + + var elm = $(evt.target); + var row = elm.parents('.row'); + + var options = row.find('.source').val(); + App.Ajax.request(App.Env.world+'.unsuspend', {spell: options}, function(reply) { + if (reply.result) { + //var tpl = App.Templates.get('SUSPENDED_TPL_NOT_SUSPENDED', 'general'); + //$(elm).replaceWith(tpl.finalize()); + App.Pages.prepareHTML(); + App.Helpers.updateScreen(); + } + else { + return App.Helpers.alert('Failed to suspend'); + } + }); } // do_action_form_help @@ -230,3 +266,56 @@ App.Actions.backup_db = function(evt) { alert('TODO'); } + +App.Actions.add_form_ns = function(evt) +{ + var elm = $(evt.target); + + form = elm.parents('.form:first'); + var total_nses = $(form).find('.ns-entry').length; + if (total_nses == App.Settings.NS_MAX) { + return App.Helpers.alert('Maximum number of NS cannot be more than ' + App.Settings.NS_MAX); + } + + var tpl = App.Templates.get('NS_INPUT', 'user'); + tpl.set(':NAME', ''); + tpl.set(':NS_LABEL', 'NS'); + elm.before(tpl.finalize()); + + if ((total_nses + 1) == App.Settings.NS_MAX ) { // added last NS + $('.additional-ns-add', form).addClass('hidden'); + } + + $(form).find('.ns-entry').each(function(i, o) + { + $(o).find('label').text('NS #' + (i + 1)); + $(o).find('input').attr('name', 'NS' + (i + 1)); + }); +} + +App.Actions.delete_ns = function(evt) +{ + var elm = $(evt.target); + + form = elm.parents('.form:first'); + var total_nses = $(form).find('.ns-entry').length; + if (total_nses == App.Settings.NS_MIN) { + return App.Helpers.alert('Minimum number of NS is ' + App.Settings.NS_MIN); + } + + var form = elm.parents('.form:first'); + $(elm).parents('.form:first').find('.additional-ns-add').removeClass('hidden'); + $(elm).parents('.ns-entry').remove(); + + $(form).find('.ns-entry').each(function(i, o) + { + $(o).find('label').text('NS #' + (i + 1)); + $(o).find('input').attr('name', 'NS' + (i + 1)); + }); +} + +App.Actions.view_full_ns_list = function(evt) +{ + var elm = $(evt.target); + App.Helpers.openInnerPopup(elm, $(elm).parents('.prop-box').find('.ns-full-list:first').html()); +} diff --git a/web/js/html.js b/web/js/html.js index 396e3569..64c440d2 100644 --- a/web/js/html.js +++ b/web/js/html.js @@ -1,6 +1,6 @@ App.HTML.setTplKeys = function(tpl, o, empty) { - var empty = empty || '-'; + var empty = empty || ''; fb.log(empty); tpl.set(':source', $.toJSON(o).replace(/'/gi, "\\'")) $(o).each(function(i, object) @@ -12,7 +12,7 @@ App.HTML.setTplKeys = function(tpl, o, empty) tpl.set(':' + key, val || ''); } else { - tpl.set(':' + key, val || '-'); + tpl.set(':' + key, val || ''); } }); }); @@ -138,14 +138,14 @@ App.HTML.Build.ip_entry = function(o) var tpl = App.Templates.get('ENTRY', 'ip'); tpl = App.HTML.setTplKeys(tpl, o); - if (App.Constants.SUSPENDED_YES == o.SUSPENDED) { + /*if (App.Constants.SUSPENDED_YES == o.SUSPENDED) { var sub_tpl = App.Templates.get('SUSPENDED_TPL_ENABLED', 'ip'); } else { var sub_tpl = App.Templates.get('SUSPENDED_TPL_DISABLED', 'ip'); - } + }*/ - tpl.set(':SUSPENDED_TPL', sub_tpl.finalize()); + tpl.set(':SUSPENDED_TPL', ''); return tpl.finalize(); } @@ -163,14 +163,14 @@ App.HTML.Build.dns_entry = function(o, is_new) tpl.set(':DATE', now.format("d.mm.yyyy")); } - if (App.Constants.SUSPENDED_YES == o.SUSPEND) { + /*if (App.Constants.SUSPENDED_YES == o.SUSPEND) { var sub_tpl = App.Templates.get('SUSPENDED_TPL_NOT_SUSPENDED', 'general'); } else { var sub_tpl = App.Templates.get('SUSPENDED_TPL_SUSPENDED', 'general'); - } + }*/ - tpl.set(':SUSPENDED_TPL', sub_tpl.finalize()); + tpl.set(':SUSPENDED_TPL', ''); return tpl.finalize(); } @@ -190,13 +190,41 @@ App.HTML.Build.user_entry = function(o, key) var tpl = App.Templates.get('ENTRY', 'user'); tpl = App.HTML.setTplKeys(tpl, o); - if (App.Constants.SUSPENDED_YES == o.SUSPENDED) { + /*if (App.Constants.SUSPENDED_YES == o.SUSPENDED) { var sub_tpl = App.Templates.get('SUSPENDED_TPL_SUSPENDED', 'general'); } else { 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() != '') { + var tpl_ns = App.Templates.get('NS_RECORD', 'user'); + tpl_ns.set(':NAME', o['NS'+index]); + var tpl_finalized = tpl_ns.finalize(); + ns_full[ns_full.length++] = tpl_finalized; + if (i < App.Settings.USER_VISIBLE_NS) { + ns[ns.length++] = tpl_finalized; + } + } + }); + + if (ns_full.length <= App.Settings.USER_VISIBLE_NS) { + tpl.set(':NS', ns.done()); } - tpl.set(':SUSPENDED_TPL', sub_tpl.finalize()); + else { + var ns_custom = App.Templates.get('NS_MINIMIZED', 'user'); + ns_custom.set(':NS_MINI', ns.done()); + ns_custom.set(':NS_FULL', ns_full.done()); + ns_custom.set(':MORE_NUMBER', Math.abs(App.Settings.USER_VISIBLE_NS - ns_full.length)); + tpl.set(':NS', ns_custom.finalize()); + } + return tpl.finalize(); } @@ -220,7 +248,22 @@ App.HTML.Build.user_form = function(options, id) tpl.set(':save_button', 'SAVE'); } - options = !App.Helpers.isEmpty(options) ? options : {'CONTACT':'', 'PASSWORD':'','LOGIN_NAME':'','LNAME':'', 'FNAME':''}; + options = !App.Helpers.isEmpty(options) ? options : App.Empty.USER; + + // NS + var ns = []; + $([3,4,5,6,7,8]).each(function(i, index) + {fb.warn(options); + if (options['NS'+index].trim() != '') { + var tpl_ns = App.Templates.get('NS_INPUT', 'user'); + tpl_ns.set(':NS_LABEL', 'NS #' + (index)); + tpl_ns.set(':NAME', options['NS'+index]); + ns[ns.length++] = tpl_ns.finalize(); + } + }); + ns[ns.length++] = App.Templates.get('PLUS_ONE_NS', 'user').finalize(); + + tpl.set(':NS', ns.done()); tpl = App.HTML.setTplKeys(tpl, options, true); tpl = App.HTML.Build.user_selects(tpl, options); @@ -491,7 +534,7 @@ App.HTML.Build.db_selects = function(tpl, options) App.HTML.Build.ip_selects = function(tpl, options) { // OWNER - var users = App.Env.initialParams.IP.SYS_USERS || ['Skid']; + var users = App.Env.initialParams.IP.SYS_USERS; var opts = App.HTML.Build.options(users, options.OWNER); tpl.set(':owner_options', opts); diff --git a/web/js/model.js b/web/js/model.js index b7a0e5ff..c97828ce 100644 --- a/web/js/model.js +++ b/web/js/model.js @@ -77,6 +77,7 @@ App.Model.add = function(values, source_json) App.Ref.CONTENT..replaceWith(tpl);*/ // todo: reply.data; App.Pages.prepareHTML(); + App.Helpers.updateScreen(); } }); } @@ -114,8 +115,11 @@ App.Model.update = function(values, source_json, elm) App.Helpers.Warn('Changes were not applied'); } else { - var tpl = App.HTML.Build[build_method](reply.data); + /*var tpl = App.HTML.Build[build_method](reply.data); $(elm).replaceWith(tpl); + App.Helpers.updateScreen();*/ + // todo: reply.data; + App.Pages.prepareHTML(); App.Helpers.updateScreen(); } // TODO: ! diff --git a/web/js/templates.js b/web/js/templates.js index d8c2e2b6..a69f585a 100644 --- a/web/js/templates.js +++ b/web/js/templates.js @@ -32,7 +32,7 @@ App.Templates.html = { select_option: [''], error_elm: ['
~!:ERROR~!
'], SUSPENDED_TPL_NOT_SUSPENDED : ['enabled'], - SUSPENDED_TPL_SUSPENDED : ['disabled'] + SUSPENDED_TPL_SUSPENDED : ['suspended'] }, popup: { error: ['

Important: An Error Has Occured.


    Something went wrong and some of your actions can be not saved in system. Mostly, it happens when you have network connection errors.
,    However, please notify us about the situation. It would be helpfull if you will write us approximate time the error occured and last actions you were performing. You send your petition on this email: BLABLA,

Sorry for inconvinience. (We recommend you to reload the page)
'] @@ -47,17 +47,17 @@ App.Templates.html = { \ \
~!:title~!
\ -
\ + \
\ \ \ - \ + \
\
\ \
\ - \ + \  \
\
\ @@ -71,11 +71,11 @@ App.Templates.html = {
\
\ \ - \ + \
\
\ \ - \ + \
\
\ \ @@ -171,11 +171,11 @@ App.Templates.html = { \ \
~!:title~!
\ -
\ + \
\ \ - \ + \
\
\ \ @@ -192,7 +192,7 @@ App.Templates.html = {
\
\ \ - \ + \
\
\ \ @@ -276,12 +276,24 @@ App.Templates.html = { SUSPENDED_TPL_DISABLED : ['suspended'] }, user: { + NS_MINIMIZED: ['~!:NS_MINI~!\ + \ + ~!:MORE_NUMBER~! more\ + '], + /*NS_RECORD_POPUP_WRAP: ['
    ~!:CONTENT~!
'], + NS_RECORD_POPUP: ['
  • ~!:NAME~!
  • '],*/ + NS_RECORD: ['~!:NAME~!'], + NS_INPUT: ['
    \ + \ + \ +
    '], + PLUS_ONE_NS: [''], ENTRIES_WRAPPER: ['
    ~!:content~!
    '], - FORM: ['
    \ + FORM: ['
    \ \ \
    ~!:title~!
    \ -
    \ + \
    \ \ @@ -320,20 +332,21 @@ App.Templates.html = {
    \
    \ \ - \ + \
    \
    \ \ - \ + \
    \ -