DVHMA/DVHMA-OpenUI5/www/resources/sap/m/DateRangeSelection.js

7 lines
8.4 KiB
JavaScript
Raw Normal View History

/*!
* SAP UI development toolkit for HTML5 (SAPUI5/OpenUI5)
* (c) Copyright 2009-2015 SAP SE or an SAP affiliate company.
* Licensed under the Apache License, Version 2.0 - see LICENSE.txt.
*/
sap.ui.define(['jquery.sap.global','./DatePicker','./library'],function(q,D,l){"use strict";var a=D.extend("sap.m.DateRangeSelection",{metadata:{library:"sap.m",properties:{delimiter:{type:"string",group:"Misc",defaultValue:'-'},secondDateValue:{type:"object",group:"Data",defaultValue:null},from:{type:"object",group:"Misc",defaultValue:null,deprecated:true},to:{type:"object",group:"Misc",defaultValue:null,deprecated:true}},events:{change:{parameters:{from:{type:"object"},to:{type:"object"}}}}}});(function(){a.prototype.init=function(){D.prototype.init.apply(this,arguments);this._bIntervalSelection=true;};a.prototype.onkeypress=function(e){if(e.charCode){var t=this;var f=d(t);var s=c(t);var A=f.sAllowedCharacters+s+" ";var C=String.fromCharCode(e.charCode);if(C&&f.sAllowedCharacters&&A.indexOf(C)<0){e.preventDefault();}}};a.prototype._getPlaceholder=function(){var p=this.getPlaceholder();if(!p){p=this.getDisplayFormat();if(!p){p="medium";}if(p==="short"||p==="medium"||p==="long"){var L=sap.ui.getCore().getConfiguration().getFormatSettings().getFormatLocale();var o=sap.ui.core.LocaleData.getInstance(L);p=o.getDatePattern(p);}var t=this;var s=c(t);if(s&&s!==""){p=p+" "+s+" "+p;}}return p;};a.prototype.setValue=function(v){if(v!==this.getValue()){this._lastValue=v;}else{return this;}this.setProperty("value",v,true);this._bValid=true;var e=[undefined,undefined];if(v){e=this._parseValue(v);e=b(this,e[0],e[1]);if(!e[0]){this._bValid=false;q.sap.log.warning("Value can not be converted to a valid dates",this);}}if(this._bValid){this.setProperty("dateValue",e[0],true);this.setProperty("secondDateValue",e[1],true);}if(this.getDomRef()){var o=this._formatValue(e[0],e[1]);if(this._$input.val()!==o){this._$input.val(o);this._setLabelVisibility();this._curpos=this._$input.cursorPos();}}return this;};a.prototype.setFrom=function(f){this.setDateValue(f);};a.prototype.getFrom=function(){return this.getDateValue();};a.prototype.setTo=function(t){this.setSecondDateValue(t);};a.prototype.getTo=function(){return this.getSecondDateValue();};a.prototype.setDateValue=function(o){if(q.sap.equal(this.getDateValue(),o)){return this;}if(o&&(o.getTime()<this._oMinDate.getTime()||o.getTime()>this._oMaxDate.getTime())){this._bValid=false;}else{this._bValid=true;this.setProperty("dateValue",o,true);}var s=this.getSecondDateValue();var v=this._formatValue(o,s);if(v!==this.getValue()){this._lastValue=v;}this.setProperty("value",v,true);if(this.getDomRef()){var O=this._formatValue(o,s);if(this._$input.val()!==O){this._$input.val(O);this._setLabelVisibility();this._curpos=this._$input.cursorPos();}}return this;};a.prototype.setSecondDateValue=function(s){if(q.sap.equal(this.getSecondDateValue(),s)){return this;}if(s&&(s.getTime()<this._oMinDate.getTime()||s.getTime()>this._oMaxDate.getTime())){this._bValid=false;}else{this._bValid=true;this.setProperty("secondDateValue",s,true);}var o=this.getDateValue();var v=this._formatValue(o,s);if(v!==this.getValue()){this._lastValue=v;}this.setProperty("value",v,true);if(this.getDomRef()){var O=this._formatValue(o,s);if(this._$input.val()!==O){this._$input.val(O);this._setLabelVisibility();this._curpos=this._$input.cursorPos();}}return this;};a.prototype._parseValue=function(v){var f;var e=[];var o,g;var t=this;var s=c(t);if((s&&s!=="")&&v){e=v.split(s);if(e.length===2){if(e[0].slice(e[0].length-1,e[0].length)==" "){e[0]=e[0].slice(0,e[0].length-1);}if(e[1].slice(0,1)==" "){e[1]=e[1].slice(1);}}else{e=v.split(" "+s+" ");}if(e.length<2){var h=v.split(" ");if(h.length===2){e=h;}}}if(v&&e.length<=2){f=d(t);if((!s||s==="")||e.length===1){o=f.parse(v);}else if(e.length===2){o=f.parse(e[0]);g=f.parse(e[1]);if(!o||!g){o=undefined;g=undefined;}}}return[o,g];};a.prototype._formatValue=function(o,s){var v="";var t=this;var e=c(t);if(o){var f;f=d(t);if(e&&e!==""&&s){v=f.format(o)+" "+e+" "+f.format(s);}else{v=f.format(o);}}return v;};a.prototype.onChange=function(){if(!this.getEditable()||!this.getEnabled()){return;}var v=this._$input.val();var e=[undefined,undefined];this._bValid=true;if(v!=""){e=this._parseValue(v);e=b(this,e