Index: branches/1.2.x/platform/inc/form_manager.js =================================================================== diff -u -N --- branches/1.2.x/platform/inc/form_manager.js (revision 0) +++ branches/1.2.x/platform/inc/form_manager.js (revision 15526) @@ -0,0 +1,544 @@ +function FormManager() { } + +FormManager.init = function ($settings) { + $.ajaxSetup( {cache: false} ); + + this.url = ''; + this.fieldMask = '#PREFIX#[#ID#][#FIELD_NAME#]'; + + this.noErrorsHTML = ''; + this.checkTimeout = 1000; + this.pendingChecks = {}; + + this.fields = {}; + this.errors = {}; + this.fieldTypes = {}; + this.forms = {}; + this.fieldWatermarks = {}; + + this.xhrRequests = []; + + $.extend(this, $settings); +} + +FormManager.resetFields = function ($prefix) { + this.fields[$prefix] = []; +} + +FormManager.registerField = function ($prefix, $field, $watermark, $field_type) { + // fields are registered before form -> store them in separate array + if (!this.fields[$prefix]) { + this.fields[$prefix] = []; + } + + if ($watermark === undefined) { + $watermark = ''; + } + + this.fieldWatermarks[$prefix + '_' + $field] = $watermark; + + this.fields[$prefix].push($field); + + if ($field_type !== undefined) { + this.fieldTypes[$prefix + '_' + $field] = $field_type; + } +} + +FormManager.unregisterField = function ($prefix, $field) { + var $field_index = array_search($field, this.fields[$prefix]); + + this.fields[$prefix].splice($field_index, 1); + + delete this.fieldWatermarks[$prefix + '_' + $field]; + delete this.fieldTypes[$prefix + '_' + $field]; +} + + +FormManager.getFieldMask = function ($prefix) { + return this.fieldMask.replace('#PREFIX#', $prefix).replace('#ID#', this.form_param($prefix, 'id')); +} + +FormManager.getField = function ($prefix, $field, $prepend, $append) { + if ($prepend === undefined) { + $prepend = ''; + } + + if ($append === undefined) { + $append = ''; + } + + var $control_id = this.getFieldMask($prefix).replace('#FIELD_NAME#', $field); + + return document.getElementById($prepend + $control_id + $append); +} + +FormManager.getBlurFields = function ($prefix, $field) { + var $field_mask = this.getFieldMask($prefix); + + switch ( this.fieldTypes[$prefix + '_' + $field] ) { + case 'swf_upload': + return this.getField($prefix, $field, undefined, '[json]'); + break; + + case 'date': + $field += '_date'; + break; + + case 'radio': + return $("input[name='" + jq($field_mask.replace('#FIELD_NAME#', $field)) + "']"); + break; + + case 'checkbox': + return get_control($field_mask, $field, undefined, '_cb'); + break; + + case 'checkboxes': + return $("input[id^='" + jq($field_mask.replace('#FIELD_NAME#', $field)) + "_']"); + break; + + case 'cc_expiration': + return $('select', this.getCell($prefix, $field, 'field')); + break; + } + + return this.getField($prefix, $field); +} + +FormManager.registerForm = function ($settings) { + var $defaults = { + url: false, // url for form submission + template: '', // template to use instead of empty string + prefix: '', // unit prefix, used in the form + enabled: true, // form submit enabled + enabledTimer: null, // timer that performs form-resubmit countdown + save_event: '', // event to use for form data processing + id: 0, // id of item being add/edited on a form + form_id: '', // form id to work with + before_close: '', // before window close callback + validation_failure: '', // on validate failure callback + immediate_validation: true // perfom validation on blur + } + + this.forms[$settings.prefix] = {}; + $.extend(this.forms[$settings.prefix], $defaults, $settings); + + // when form is registred, then all it's fields should also be registred + + if ( !this.form_param($settings.prefix, 'immediate_validation') ) { + return ; + } + + var $me = this; + + $( this.fields[$settings.prefix] ).each( + function () { + var $blur_fields = $( $me.getBlurFields($settings.prefix, this) ), + $event_name = $blur_fields.length == 1 ? 'blur' : 'click'; + + $blur_fields[$event_name]( + function ($e) { + $me.checkField(this); + } + ); + } + ); + + for (var $error_field in this.errors[$settings.prefix]) { + this.setFieldStatus($settings.prefix, $error_field, this.errors[$settings.prefix][$error_field]); + } +} + +FormManager.getURL = function ($prefix, $template, $event, $params) { + var $url = this.form_param($prefix, 'url'); + + if (!$url) { + $url = this.url; + } + + if ($template === undefined) { + $template = this.form_param($prefix, 'template'); + } + + $url = $url.replace('#TEMPLATE#', $template); + + if ($event !== undefined) { + $url += ($url.indexOf('?') == -1 ? '?' : '&') + 'events[' + $prefix + ']=' + $event; + } + + if ( typeof($params) == 'object' ) { + for (key in $params) { + $url += ($url.indexOf('?') == -1 ? '?' : '&') + key + '=' + $params[key]; + } + } + + return $url; +} + +FormManager.processResponse = function ($prefix, $data, $add_params) { + // enable form back +// alert('enabling for for [' + $prefix + '] in processResponse'); + + if ( $add_params !== undefined ) { + $add_params.response = $data; + } + else { + $add_params = {response: $data}; + } + + this.clearErrors($prefix); + + if ($data.status == 'OK') { + var $next_template = this.getNextTemplate($prefix, $data); + + if ( $next_template || $data.do_refresh || $data.redirect_to ) { + var $before_close = this.getFormParamOverride($prefix, 'before_close', $add_params); + + if ( $.isFunction($before_close) ) { + $before_close.call(this, $data, $add_params); + } + + if ( $next_template ) { + // load another template instead of current form + $('#TB_ajaxContent').html('').load( this.getURL($prefix, $next_template, undefined, $data.params) ); + } + else if ( $data.do_refresh ) { + // refresh whole page + window.location.href = window.location.href; + } + else if ( $data.redirect_to ) { + // redirect to given page + window.location.href = $data.redirect_to; + } + } + else { + // close form without refreshing the page + this.closeForm($prefix, $data, $add_params); + } + } + else { + // set new errors + for ($field in $data.field_errors) { + this.setFieldStatus($prefix, $field, $data.field_errors[$field]); + } + + var $validation_failure = this.form_param($prefix, 'validation_failure'); + + if ( $.isFunction($validation_failure) ) { + $validation_failure.call(this, $data, $add_params); + } + } + + this.enableForm($prefix, true); + +// var $me = this; +// setTimeout(function () { $me.enableForm($prefix, true); }, 1000); +} + +/** + * Clear errors from all from fields + * + * @param $prefix + */ +FormManager.clearErrors = function ($prefix) { + var $fields = this.fields[$prefix]; + + if (typeof($fields) == 'undefined') { + $fields = []; + } + + this.errors[$prefix] = {}; + + for (var $i = 0; $i < $fields.length; $i++) { + this.setFieldStatus($prefix, $fields[$i]); + } +} + +FormManager.getNextTemplate = function ($prefix, $responce) { + if ( $responce.next_template && $responce.next_template != '' ) { + return $responce.next_template; + } + else if ( this.form_param($prefix, 'next_template') ) { + return this.form_param($prefix, 'next_template'); + } + + return false; +} + +FormManager.getCell = function ($prefix, $field_name, $cell_type) { + $field_name = $field_name.replace(/_(date|time)$/, ''); + + return this.getField($prefix, $field_name, undefined, '_' + $cell_type + '_cell'); +} + +FormManager.setFieldStatus = function ($prefix, $field_name, $error_msg) { + var field_cell = this.getCell($prefix, $field_name, 'field'); + var status_cell = this.getCell($prefix, $field_name, 'status'); + + if ( $error_msg === undefined || !$error_msg ) { + $error_msg = ''; + } + + if ( !field_cell ) { + if (!this.errors[$prefix]) { + this.errors[$prefix] = {}; + } + + this.errors[$prefix][$field_name] = $error_msg; + + /*if(typeof console === 'object') { + console.log('FormManager: Error field "' + $field_name + '" missing.'); + }*/ + + return ; + } + + if ($error_msg === undefined || !$error_msg) { + // show OK + $(field_cell).parents('tr:first').removeClass('error').addClass('ok'); + $(status_cell).removeClass('field-error').html(this.noErrorsHTML); + + var $fields = this.fields[$prefix]; + + for (var $i = 0; $i < $fields.length; $i++) { + if ( this.fieldHasError($prefix, $fields[$i]) ) { + return ; + } + } + } + else { + // show error message + $(field_cell).parents('tr:first').removeClass('ok').addClass('error'); + $(status_cell).addClass('field-error').html($error_msg); + } +} + +FormManager.fieldHasError = function ($prefix, $field) { + var status_cell = this.getField($prefix, $field, undefined, '_status_cell'); + + return $.trim( $(status_cell).html() ) != $.trim( this.noErrorsHTML ); +} + +FormManager.checkField = function ($input, $delayed) { + if ( !$input.id.match(/^(.*?)\[.*?\]\[(.*?)\].*?$/) ) { + return ; + } + + var $prefix = RegExp.$1; + var $field = RegExp.$2.replace(/(_date|_time)$/, ''); + + if ( $field.match(/(.*)(Month|Year)$/) && this.fieldTypes[$prefix + '_' + RegExp.$1 + 'Date'] == 'cc_expiration' ) { + $field = RegExp.$1 + 'Date'; + } + + if ( this.pendingChecks[$field] ) { + clearTimeout( this.pendingChecks[$field] ); + delete this.pendingChecks[$field]; + } + + var $me = this; + + this.pendingChecks[$field] = setTimeout( + function () { + $me.validateField($prefix, $field, $input) + }, + ($delayed === true ? this.checkTimeout : 0) + ); +} + +FormManager.validateField = function ($prefix, $field, $input) { + var $me = this; + + var $request = $.post( + this.getURL($prefix, undefined, 'OnValidateField') + '&field=' + encodeURIComponent($field) + '&' + $input.name + '=' + encodeURIComponent($input.value), + this._getFormFields($prefix), + function ($data) { + $data = eval('(' + $data + ')'); + $me.setFieldStatus($prefix, $field, $data.status == 'OK' ? undefined : $data.status); + + // show/hide general error notice + $('#' + $prefix + '_error_message').toggle(!$.isArray($data.other_errors)); + } + ); + + this.xhrRequests.push($request); +}; + +FormManager.form_param = function ($prefix, $param, $value) { + if ( this.forms[$prefix] === undefined ) { + return ''; + } + + if ($value === undefined) { + return this.forms[$prefix][$param]; + } + + this.forms[$prefix][$param] = $value; +} + +FormManager.getFormParamOverride = function ($prefix, $param, $overrides) { + if ( $overrides[$param] !== undefined ) { + return $overrides[$param]; + } + + return this.form_param($prefix, $param); +} + +/* === related to form opening/closing/submitting === */ +FormManager.openForm = function ($prefix, $template, $width, $height, $source_form, $params) { + var $url = this.getURL($prefix, $template, undefined, $params); + + $url += ($url.indexOf('?') == -1 ? '?' : '&') + 'width=' + $width + '&height=' + $height + '&modal=true'; + + var $tb_settings = {url: $url}; + + if ($source_form !== undefined) { + $tb_settings.postParams = $($source_form).serialize(); + } + + TB.show($tb_settings); +} + +FormManager.validateAll = function ($prefix, $status) { + var $fields = this.fields[$prefix]; + + for (var $i = 0; $i < $fields.length; $i++) { + this.setFieldStatus($prefix, $fields[$i], $status); + } +} + +FormManager.closeForm = function ($prefix, $data, $add_params) { + if ( $data === undefined ) { + $data = {}; + } + + if ( $add_params === undefined ) { + $add_params = {}; + } + + var $before_close = this.getFormParamOverride($prefix, 'before_close', $add_params); + + this.cancelXHRRequests(); + this.validateAll($prefix); + + if ( $.isFunction($before_close) ) { + var $result = $before_close.call(this, $data, $add_params); + + if ($result === false) { + return; + } + } + + TB.remove(); +} + +FormManager._getFormFields = function ($prefix) { + var $old_values = {}, + $fields = this.fields[$prefix]; + + if (typeof($fields) == 'undefined') { + $fields = []; + } + + // remove watermarks from input fields + for (var $i = 0; $i < $fields.length; $i++) { + var $control = this.getField($prefix, $fields[$i]), + $watermark = this.fieldWatermarks[ $prefix + '_' + $fields[$i] ]; + + if ( $control ) { + $old_values[$fields[$i]] = $control.value; + + if ( $watermark !== undefined && $control.value == $watermark ) { + $control.value = ''; + } + } + } + + var form = document.getElementById( this.form_param($prefix, 'form_id')), + $form_fields = $(form).serialize(); + + // restore original values into input fields + for (var $i = 0; $i < $fields.length; $i++) { + var $control = this.getField($prefix, $fields[$i]); + + if ( $control ) { + $control.value = $old_values[$fields[$i]]; + } + } + + return $form_fields; +} + +FormManager.enableForm = function ($prefix, $enabled) { + if ($enabled === undefined) { + $enabled = true; + } + + if ($enabled) { + clearTimeout( this.form_param($prefix, 'enabledTimer') ); + this.form_param($prefix, 'enabledTimer', null); + } + else { + var $me = this; + + // set timer for 10 seconds to enable form back (just in case if ajax responce fails) + var $timer = setTimeout( + function () { +// alert('enabling for for [' + $prefix + '] in setTimeout'); + $me.enableForm($prefix, true); + } + , 10000 + ); + + this.form_param($prefix, 'enabledTimer', $timer); + } + + this.form_param($prefix, 'enabled', $enabled); +} + +FormManager.cancelXHRRequests = function () { + while ( this.xhrRequests.length > 0 ) { + this.xhrRequests.shift().abort(); + } +} + +FormManager.submitForm = function ($prefix, $add_params) { + if ( !this.form_param($prefix, 'enabled') ) { + return ; + } + + // disable form + this.enableForm($prefix, false); + + var $me = this; + this.cancelXHRRequests(); + + $.post( + this.getURL( $prefix, undefined, this.form_param($prefix, 'save_event') ), + this._getFormFields($prefix), + function ($data) { + var $redirect = TB.parseRedirect($data); + + if ( $redirect !== false ) { + window.location.href = $redirect; + + return ; + } + + $me.processResponse($prefix, eval('(' + $data + ')'), $add_params); + } + ) +} + +FormManager.beforeClose = function () { + this.cancelXHRRequests(); + + for (var $prefix in this.forms) { + var $before_close = this.form_param($prefix, 'before_close'); + + this.clearErrors($prefix); + + if ( $.isFunction($before_close) ) { + $before_close.call(this, {}, {}); + } + } +} Index: branches/1.2.x/platform/designs/default_design.des.tpl =================================================================== diff -u -N -r15269 -r15526 --- branches/1.2.x/platform/designs/default_design.des.tpl (.../default_design.des.tpl) (revision 15269) +++ branches/1.2.x/platform/designs/default_design.des.tpl (.../default_design.des.tpl) (revision 15526) @@ -26,6 +26,13 @@ + - - "> - - - - " value="" /> - - - + + < class="field-error" id="_status_cell"> + + + + > - - "> - - - -
-
- " value="" tabindex="" maxlength="" style=""> - - - - + + + + + + + + + + + + + + + + + -
_input" style="display: none;"> +
style="display: none;">
@@ -147,188 +165,128 @@ - - "> - - - + + + - - - - - + + - - "> - - - -
-
- " id="" value="" tabindex="" style="" /> - - - - + + + + - - "> - - - -
-
- " tabindex="" style=""> - - () - - [upload]" value="" /> - - - + + + + + () + + + - - "> - - - -
-
- - " target="_blank"> - - -
- - - - - -
- " name="" value="0" /> - " onchange="update_checkbox(this, document.getElementById(''));"> - - -
-
- " tabindex="" style=""> - [upload]" value="" />
- " value="" style=""> - - - + + + + + + +
+ + + + + +
+ + + + +
+
+ + +
+ +
- - "> - - - -
-
- - "> - - -
- - - - - -
- " name="" value="0" /> - " onchange="update_checkbox(this, document.getElementById(''));"> - - -
-
- " tabindex="" style=""> - [upload]" value="" /> - - - + + + + + + +
+ + + + + +
+ + + + +
+
+ + +
- " id="" value="" /> + - - "> - - - -
-
- " id="" value="" tabindex="" size="" style="" datepickerIcon="img/calendar_icon.gif"> () - - " id="" value="" /> - - - + + +  () + + + + - - "> - - - -
-
- " id="" value="" tabindex="" size="" style="">  - () + + +   + () - " id="" value="" /> - - - + + - - "> - - - -
-
- " id="" value="" tabindex="" size="" style="" datepickerIcon="core/admin_templates/img/calendar_icon.gif"> - () - -  " id="" value="" tabindex="" size="" style=""> () - - - + + + + () + +   () + - - "> - - - -
-
- - - - + + + + -
_input" style="display: none;"> +
style="display: none;">
@@ -348,236 +306,185 @@
- - "> - - - + + + - - - - - + + - + - + - - "> - - - -
+ + + " name="" style=""> - - - - - - - - - + + - "> - - - -
-
+ + - -    + $('#timezone_group').val($current_timezone_group).change(); + } + ); + - - - - + +    + + +
- " style="" name="" id="_" value="">  + name="" id="_" value="">  - " style="" name="" id="_" value="">  + name="" id="_" value="">  - - "> - - - -
-
- - - - - - - - + + + + + + + + - - "> - - - -
-
- " alt=""/>
- img/s.gif" width="1" height="5" alt=""/>
- " value="" tabindex="" style=""> - - - + + + <inp2:m_Phrase name='$title' no_editing='1'/>
+
+ +
- - "> - - - -
-
- " name="" value="" /> - " type="checkbox" id="_cb_" name="_cb_" style="" onchange="update_checkbox(this, document.getElementById(''));"> - - - - + + + + style="" onchange="update_checkbox(this, document.getElementById(''));"> + - "> - - + + - -
-
+
- +
+ + - " onclick="$ItemCategories.AddCategory('»&nbsp;', $delete_button, );"/>
+
+ + -
-
+ : +
- + + +
+
- - - : - - + - - - -
- - - - - - - + +
@@ -588,16 +495,12 @@ - - "> - - - - - - - - - - + + + + + + + + \ No newline at end of file Index: branches/1.2.x/in-commerce/elements/forms.elm.tpl =================================================================== diff -u -N -r14593 -r15526 --- branches/1.2.x/in-commerce/elements/forms.elm.tpl (.../forms.elm.tpl) (revision 14593) +++ branches/1.2.x/in-commerce/elements/forms.elm.tpl (.../forms.elm.tpl) (revision 15526) @@ -16,20 +16,11 @@ - "> - - - -
-
- - - -
- - - - + + + +
+
Index: branches/1.2.x/in-link/links/modify_link.tpl =================================================================== diff -u -N -r14274 -r15526 --- branches/1.2.x/in-link/links/modify_link.tpl (.../modify_link.tpl) (revision 14274) +++ branches/1.2.x/in-link/links/modify_link.tpl (.../modify_link.tpl) (revision 15526) @@ -86,20 +86,17 @@ - "> - - - - - - () - - "> - - "> + + + + + () - - + "> + + "> + + Index: branches/1.2.x/platform/inc/script.js =================================================================== diff -u -N -r14993 -r15526 --- branches/1.2.x/platform/inc/script.js (.../script.js) (revision 14993) +++ branches/1.2.x/platform/inc/script.js (.../script.js) (revision 15526) @@ -41,6 +41,13 @@ } }; +function get_control($mask, $field, $append, $prepend) { + $append = $append !== undefined ? '_' + $append : ''; + $prepend = $prepend !== undefined ? $prepend + '_' : ''; + + return document.getElementById($prepend + $mask.replace('#FIELD_NAME#', $field) + $append); +} + // ItemCategories class function ItemCategories($table_id, $field_id, $primary_category, $phrases) { this.CategoryTable = document.getElementById($table_id); Index: branches/1.2.x/in-bulletin/elements/forms.elm.tpl =================================================================== diff -u -N -r14274 -r15526 --- branches/1.2.x/in-bulletin/elements/forms.elm.tpl (.../forms.elm.tpl) (revision 14274) +++ branches/1.2.x/in-bulletin/elements/forms.elm.tpl (.../forms.elm.tpl) (revision 15526) @@ -1,32 +1,28 @@ - - "> - - - '); return false;"> - img/toolbar/bold_icon.png" border="0"/> - - '); return false;"> - img/toolbar/italic_icon.png" border="0"/> - - '); return false;"> - img/toolbar/underline_icon.png" border="0"/> - - '); return false;"> - img/toolbar/link_icon.png" border="0"/> - - '); return false;"> - img/toolbar/image_icon.png" border="0"/> - - '); return false;"> - img/toolbar/code_icon.png" border="0"/> - + + + '); return false;"> + img/toolbar/bold_icon.png" border="0"/> + + '); return false;"> + img/toolbar/italic_icon.png" border="0"/> + + '); return false;"> + img/toolbar/underline_icon.png" border="0"/> + + '); return false;"> + img/toolbar/link_icon.png" border="0"/> + + '); return false;"> + img/toolbar/image_icon.png" border="0"/> + + '); return false;"> + img/toolbar/code_icon.png" border="0"/> + -
- -
-
- - - - +
+ + + + +
\ No newline at end of file Index: branches/1.2.x/platform/my_account/my_profile.tpl =================================================================== diff -u -N -r14993 -r15526 --- branches/1.2.x/platform/my_account/my_profile.tpl (.../my_profile.tpl) (revision 14993) +++ branches/1.2.x/platform/my_account/my_profile.tpl (.../my_profile.tpl) (revision 15526) @@ -46,7 +46,7 @@ img/grey_pix.gif" width="100%" height="1" align="absmiddle" alt="" />

-
+ @@ -80,6 +80,24 @@
+ +
Index: branches/1.2.x/platform/elements/html_head.elm.tpl =================================================================== diff -u -N -r15442 -r15526 --- branches/1.2.x/platform/elements/html_head.elm.tpl (.../html_head.elm.tpl) (revision 15442) +++ branches/1.2.x/platform/elements/html_head.elm.tpl (.../html_head.elm.tpl) (revision 15526) @@ -1,4 +1,3 @@ - @@ -15,7 +14,7 @@ - + Index: branches/1.2.x/in-commerce/elements/content_boxes/checkout/billing_options.elm.tpl =================================================================== diff -u -N -r14857 -r15526 --- branches/1.2.x/in-commerce/elements/content_boxes/checkout/billing_options.elm.tpl (.../billing_options.elm.tpl) (revision 14857) +++ branches/1.2.x/in-commerce/elements/content_boxes/checkout/billing_options.elm.tpl (.../billing_options.elm.tpl) (revision 15526) @@ -31,36 +31,23 @@ - "> - - - -
-
- - / - - - - + + + / + + - "> - - - -
-
- " value="" tabindex="" style="width: 50px;"> -    - - + + +    + Index: branches/1.2.x/platform/inc/styles.css =================================================================== diff -u -N -r14857 -r15526 --- branches/1.2.x/platform/inc/styles.css (.../styles.css) (revision 14857) +++ branches/1.2.x/platform/inc/styles.css (.../styles.css) (revision 15526) @@ -203,7 +203,7 @@ font-size: 11px; } -.field-required { +.field-required, .error .field-name { color: #FF0000; }