(function (ns) { 'use strict'; /** * @alias qs.form.TranslateExtension * @constructor */ ns.TranslateExtension = function () { this.construct.apply(this, arguments); }; var proto = ns.TranslateExtension.prototype; proto.construct = function (options) { this.options = $.extend({ formId: undefined, languageToolbarContainerId: undefined, languageList: undefined, contentFields: undefined }, options || {}); this.toolbarContainer = $('#' + this.options.languageToolbarContainerId); this.initContentFields(); return this; }; proto.initContentFields = function () { this.toolbarContainer.find(':radio').bind('change', $.proxy(this.onChangeLanguageElement, this)); }; proto.onChangeLanguageElement = function (e) { var target = e.currentTarget; var contentFields = this.options.contentFields; switch (target.value) { case 'all': this.displayLanguageFields(contentFields, true); break; default: this.displayLanguageFields(contentFields, false); this.showLanguageFields(contentFields, target.value); break; } }; proto.displayLanguageFields = function (contentFields, state) { var selector = [], languageList = this.options.languageList, elementSelector, i, j; for (i in contentFields) { if (contentFields.hasOwnProperty(i)) { for (j in languageList) { if (languageList.hasOwnProperty(j)) { elementSelector = '#' + contentFields[i] + '-' + contentFields[i]; elementSelector += '_' + languageList[j] + '-element'; selector.push(elementSelector); } } } } selector = selector.join(', '); $(selector).removeClass('hidden'); if (state) { $(selector).removeClass('hidden'); } else { $(selector).addClass('hidden'); } }; proto.showLanguageFields = function (contentFields, language) { 'use strict'; var i, contentField; for (i in contentFields) { if (contentFields.hasOwnProperty(i)) { contentField = $('#' + contentFields[i] + '-' + contentFields[i] + '_' + language + '-element'); if (contentField.length) { contentField.removeClass('hidden'); } } } }; /** * @static * @param formId * @return {*} */ ns.TranslateExtension.onErrorCallback = function (formId) { var response = Qs_Form.getFormOption(formId, 'response'); if (!response.isValid) { $('#language-all').click(); } return Qs_Form.displayErrors(formId); }; })(qs.defineNS('qs.form'));