"use strict"; /**  * Licensed Materials - Property of IBM  * IBM Cognos Products: Cognos Analytics  * Copyright IBM Corp. 2015, 2016  * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.  */ define(['jquery', 'bi/admin/common/ui/WidgetView'], function ($, WidgetView) { 'use strict'; //NOSONAR: meant to be strict var RadioCheckBase = WidgetView.extend({ widgetName: $.noop, inputType: $.noop, options: { value: '' }, init: function init(options) { RadioCheckBase.inherited('init', this, arguments); var query = "input[type='" + this.inputType + "']"; if (this.element.is(query)) { this._create(); this.refresh(); } }, _create: function _create() { var cls = "bi-" + this.inputType; var wrapperCls = cls + "-wrapper"; var wrapper = $('
'); wrapper.addClass(wrapperCls); wrapper.attr('role', this.inputType); var labelEl = this.element.parent().find("label"); var labId = labelEl.attr("local_id"); labelEl.attr("id", labId); this.element.parent().attr("aria-labelledby", labId); this.element.wrap(wrapper); this.element.addClass(cls); var label = ''; this.element.after(label); wrapper = this.element.parent(); wrapper.on('primaryaction', function () { this.toggleCheck(); }.bind(this)); this._wrapper = wrapper; }, toggleCheck: function toggleCheck() { this.option('checked', !this.options.checked); }, check: function check() { this.option('checked', true); }, uncheck: function uncheck() { this.option('checked', false); }, isChecked: function isChecked() { return !!this.element.is(':checked'); }, isDisabled: function isDisabled() { return !!this.element.is(':disabled'); }, refresh: function refresh() { var checked = this.isChecked(); var disabled = this.isDisabled(); this.options.checked = checked; this.options.value = this.element.val() || ""; this.element.attr('aria-checked', checked); this._wrapper.toggleClass('checked', checked); this._wrapper.attr('aria-checked', checked); this._wrapper.toggleClass('disabled', disabled); this._wrapper.attr('aria-disabled', disabled); if (!disabled) { this._wrapper.attr('tabindex', '0'); } }, _cleanGroup: function _cleanGroup() {}, _setChecked: function _setChecked(checked) { if (this.isChecked() !== checked) { if (checked) { this._cleanGroup(); this._wrapper.addClass('checked'); this.element.prop('checked', true); this.element.attr('aria-checked', true); this._wrapper.attr('aria-checked', true); } else { this._wrapper.removeClass('checked'); this.element.prop('checked', false); this.element.attr('aria-checked', false); this._wrapper.attr('aria-checked', false); } } }, _setOption: function _setOption(key, value) { var self = this; var oldVal = this.options[key]; switch (key) { case "value": this.element.val(value); break; case "checked": this._setChecked(value); break; case "disabled": this._wrapper.toggleClass("disabled", !!value); break; default: break; } WidgetView.prototype._setOption.apply(self, arguments); switch (key) { case "checked": if (oldVal !== value) { this.trigger('change'); this.element.trigger('change'); } break; default: break; } } }); return RadioCheckBase; });