/*! * UI development toolkit for HTML5 (OpenUI5) * (c) Copyright 2009-2018 SAP SE or an SAP affiliate company. * Licensed under the Apache License, Version 2.0 - see LICENSE.txt. */ sap.ui.define(['./library','sap/ui/core/Control','sap/ui/core/EnabledPropagator','./RadioButtonGroup','sap/ui/core/library','./RadioButtonRenderer','sap/ui/core/message/MessageMixin'],function(l,C,E,R,c,a,M){"use strict";var T=c.TextAlign;var V=c.ValueState;var b=c.TextDirection;var d=C.extend("sap.m.RadioButton",{metadata:{interfaces:["sap.ui.core.IFormContent"],library:"sap.m",properties:{enabled:{type:"boolean",group:"Behavior",defaultValue:true},selected:{type:"boolean",group:"Data",defaultValue:false},groupName:{type:"string",group:"Behavior",defaultValue:'sapMRbDefaultGroup'},text:{type:"string",group:"Appearance",defaultValue:null},textDirection:{type:"sap.ui.core.TextDirection",group:"Appearance",defaultValue:b.Inherit},width:{type:"sap.ui.core.CSSSize",group:"Dimension",defaultValue:''},useEntireWidth:{type:"boolean",group:"Appearance",defaultValue:false},activeHandling:{type:"boolean",group:"Appearance",defaultValue:true},editable:{type:"boolean",group:"Behavior",defaultValue:true},valueState:{type:"sap.ui.core.ValueState",group:"Data",defaultValue:V.None},textAlign:{type:"sap.ui.core.TextAlign",group:"Appearance",defaultValue:T.Begin},valueStateText:{type:"string",group:"Misc",defaultValue:null,visibility:"hidden"}},events:{select:{parameters:{selected:{type:"boolean"}}}},associations:{ariaDescribedBy:{type:"sap.ui.core.Control",multiple:true,singularName:"ariaDescribedBy"},ariaLabelledBy:{type:"sap.ui.core.Control",multiple:true,singularName:"ariaLabelledBy"}},designtime:"sap/m/designtime/RadioButton.designtime"}});E.call(d.prototype);M.call(d.prototype);d.prototype._groupNames={};var K={HOME:"first",END:"last",NEXT:"next",PREV:"prev"};d.prototype.ontap=function(e){if(!this.getEnabled()||!this.getEditable()){return;}var p=this.getParent();if(p instanceof R&&(!p.getEnabled()||!p.getEditable())){return;}e&&e.setMarked();this.applyFocusInfo();if(!this.getSelected()){this.setSelected(true);var t=this;setTimeout(function(){t.fireSelect({selected:true});},0);}};d.prototype.ontouchstart=function(e){e.originalEvent._sapui_handledByControl=true;if(this.getEnabled()&&this.getActiveHandling()){this.$().toggleClass("sapMRbBTouched",true);}};d.prototype.ontouchend=function(e){this.$().toggleClass("sapMRbBTouched",false);};d.prototype.onsapnext=function(e){this._keyboardHandler(K.NEXT,true);e.setMarked();return this;};d.prototype.onsapnextmodifiers=function(e){this._keyboardHandler(K.NEXT,!e.ctrlKey);e.setMarked();return this;};d.prototype.onsapprevious=function(e){this._keyboardHandler(K.PREV,true);e.setMarked();return this;};d.prototype.onsappreviousmodifiers=function(e){this._keyboardHandler(K.PREV,!e.ctrlKey);e.setMarked();return this;};d.prototype.onsaphome=function(e){this._keyboardHandler(K.HOME,true);e.setMarked();return this;};d.prototype.onsaphomemodifiers=function(e){this._keyboardHandler(K.HOME,!e.ctrlKey);e.setMarked();return this;};d.prototype.onsapend=function(e){this._keyboardHandler(K.END,true);e.setMarked();return this;};d.prototype.onsapendmodifiers=function(e){this._keyboardHandler(K.END,!e.ctrlKey);e.setMarked();return this;};d.prototype._keyboardHandler=function(p,s){if(this.getParent()instanceof R){return;}var n=this._getNextFocusItem(p);n.focus();if(s&&!n.getSelected()&&n.getEditable()&&n.getEnabled()){n.setSelected(true);setTimeout(function(){n.fireSelect({selected:true});},0);}};d.prototype.getAccessibilityInfo=function(){var B=sap.ui.getCore().getLibraryResourceBundle("sap.m");return{role:"radio",type:B.getText("ACC_CTR_TYPE_RADIO"),description:(this.getText()||"")+(this.getSelected()?(" "+B.getText("ACC_CTR_STATE_CHECKED")):""),enabled:this.getEnabled(),editable:this.getEditable()};};d.prototype.getFormDoNotAdjustWidth=function(){return this.getText()?false:true;};d.prototype._getNextFocusItem=function(n){var v=this._groupNames[this.getGroupName()].filter(function(r){return(r.getDomRef()&&r.getEnabled());});var B=v.indexOf(this),i=B,e=v.length;switch(n){case K.NEXT:i=B===e-1?B:B+1;break;case K.PREV:i=B===0?0:i-1;break;case K.HOME:i=0;break;case K.END:i=e-1;break;}return v[i]||this;};d.prototype.onsapselect=function(e){e.preventDefault();this.ontap(e);};d.prototype.setEnabled=function(e){this.setProperty("enabled",e,false);return this;};d.prototype.setSelected=function(s){var o,S=this.getSelected(),g=this.getGroupName(),e=this._groupNames[g],L=e&&e.length;this.setProperty("selected",s,true);this._changeGroupName(this.getGroupName());if(!!s&&g&&g!==""){for(var i=0;i=-1){e.splice(G,1);}};d.prototype._createLabel=function(p,v){this._oLabel=new sap.m.Label(this.getId()+"-label").addStyleClass("sapMRbBLabel").setParent(this,null,true);this._oLabel.setProperty(p,v,false);};d.prototype.setTabIndex=function(t){var f=this.getFocusDomRef();this._iTabIndex=t;if(f){f.setAttribute("tabindex",t);}return this;};d.prototype.setTextAlign=function(A){this.setProperty("textAlign",A,true);if(this._oLabel){this._oLabel.setTextAlign(this.getTextAlign());}else{this._createLabel("textAlign",this.getTextAlign());}return this;};d.prototype.setValueStateText=function(t){return this.setProperty("valueStateText",t,true);};d.prototype._changeGroupName=function(n,o){var N=this._groupNames[n],O=this._groupNames[o];if(O&&O.indexOf(this)!==-1){O.splice(O.indexOf(this),1);this._setAriaPositionAttributes(o);}if(!N){N=this._groupNames[n]=[];}if(N.indexOf(this)===-1){N.push(this);this._setAriaPositionAttributes(n);}};d.prototype._setAriaPositionAttributes=function(g){var G=this._groupNames[g],r=0,i;if(!G.length||!this.getDomRef()){return;}i=G.reduce(function(i,o){return o.getDomRef()?++i:i;},0);G.forEach(function(o){var e=o.getDomRef();if(e){e.setAttribute("aria-posinset",++r);e.setAttribute("aria-setsize",i);}});};return d;});