@@ -6,11 +6,11 @@ sap.ui.define(["sap/ui/core/mvc/Controller",
66 onInit : async function ( ) {
77
88 z2ui5 . oOwnerComponent = this . getOwnerComponent ( ) ;
9- z2ui5 . oConfig . pathname = this . getView ( ) . getModel ( " http" ) . sServiceUrl ;
10- if ( z2ui5 ?. checkLocal == true ) {
11- z2ui5 . oConfig . pathname = window . location . href ;
9+ z2ui5 . oConfig . pathname = z2ui5 . oOwnerComponent . getManifest ( ) [ "sap.app" ] . dataSources . http . uri ;
10+ if ( z2ui5 ?. checkLocal == true ) {
11+ z2ui5 . oConfig . pathname = window . location . href ;
1212 } ;
13-
13+
1414 z2ui5 . oController = new Controller ( ) ;
1515 z2ui5 . oApp = this . getView ( ) . byId ( "app" ) ;
1616
@@ -200,19 +200,20 @@ sap.ui.define("z2ui5/Tree", ["sap/ui/core/Control"], (Control) => {
200200 } ,
201201
202202 setBackend ( ) {
203- z2ui5 . treeState = z2ui5 . oView . byId ( this . getProperty ( "tree_id" ) ) . getBinding ( 'items' ) . getCurrentTreeState ( ) ;
203+ z2ui5 . treeState = z2ui5 . oView . byId ( this . getProperty ( "tree_id" ) ) . getBinding ( 'items' ) . getCurrentTreeState ( ) ;
204204 } ,
205205
206206 init ( ) {
207207 z2ui5 . onBeforeRoundtrip . push ( this . setBackend . bind ( this ) ) ;
208208 } ,
209209
210- renderer ( oRm , oControl ) {
211- if ( ! z2ui5 . treeState ) return ;
210+ renderer ( oRm , oControl ) {
211+ if ( ! z2ui5 . treeState ) return ;
212212 setTimeout ( ( id ) => {
213- z2ui5 . oView . byId ( id ) . getBinding ( 'items' ) . setTreeState ( z2ui5 . treeState ) ;
214- } , 100 , oControl . getProperty ( "tree_id" ) ) ;
215- } } ) ;
213+ z2ui5 . oView . byId ( id ) . getBinding ( 'items' ) . setTreeState ( z2ui5 . treeState ) ;
214+ } , 100 , oControl . getProperty ( "tree_id" ) ) ;
215+ }
216+ } ) ;
216217} ) ;
217218
218219sap . ui . define ( "z2ui5/Scrolling" , [ "sap/ui/core/Control" ] , ( Control ) => {
@@ -243,7 +244,7 @@ sap.ui.define("z2ui5/Scrolling", ["sap/ui/core/Control"], (Control) => {
243244 try {
244245 const element = document . getElementById ( `${ z2ui5 . oView . byId ( item . ID ) . getId ( ) } -inner` ) ;
245246 item . V = element ? element . scrollTop : 0 ;
246- } catch { }
247+ } catch { }
247248 }
248249 } ) ;
249250 }
@@ -668,7 +669,7 @@ sap.ui.define("z2ui5/MultiInputExt", ["sap/ui/core/Control", "sap/m/Token", "sap
668669 let table = z2ui5 . oView . byId ( this . getProperty ( "MultiInputId" ) ) ;
669670 if ( ! table ) {
670671 try {
671- // table = Core.byId(Element.getElementsByName(this.getProperty("MultiInputName"))[0].id.replace('-inner', ''));
672+ // table = Core.byId(Element.getElementsByName(this.getProperty("MultiInputName"))[0].id.replace('-inner', ''));
672673 } catch ( e ) {
673674 return ;
674675 }
@@ -697,7 +698,7 @@ sap.ui.define("z2ui5/MultiInputExt", ["sap/ui/core/Control", "sap/m/Token", "sap
697698
698699sap . ui . define ( "z2ui5/SmartMultiInputExt" , [ "sap/ui/core/Control" , "sap/m/Token" , "sap/ui/core/Core" , "sap/ui/core/Element" ] , ( Control ) => {
699700 "use strict" ;
700-
701+
701702 return Control . extend ( "z2ui5.SmartMultiInputExt" , {
702703 metadata : {
703704 properties : {
@@ -711,7 +712,8 @@ sap.ui.define("z2ui5/SmartMultiInputExt", ["sap/ui/core/Control", "sap/m/Token",
711712 type : "Array"
712713 } ,
713714 rangeData : {
714- type : "Array"
715+ type : "Array" ,
716+ defaultValue : [ ]
715717 } ,
716718 checkInit : {
717719 type : "Boolean" ,
@@ -725,15 +727,15 @@ sap.ui.define("z2ui5/SmartMultiInputExt", ["sap/ui/core/Control", "sap/m/Token",
725727 }
726728 } ,
727729 } ,
728-
730+
729731 init ( ) {
730732 z2ui5 . onAfterRendering . push ( this . setControl . bind ( this ) ) ;
731733 } ,
732-
734+
733735 onTokenUpdate ( oEvent ) {
734736 this . setProperty ( "addedTokens" , [ ] ) ;
735737 this . setProperty ( "removedTokens" , [ ] ) ;
736-
738+
737739 if ( oEvent . mParameters . type == "removed" ) {
738740 let removedTokens = [ ] ;
739741 oEvent . mParameters . removedTokens . forEach ( ( item ) => {
@@ -755,9 +757,33 @@ sap.ui.define("z2ui5/SmartMultiInputExt", ["sap/ui/core/Control", "sap/m/Token",
755757 ) ;
756758 this . setProperty ( "addedTokens" , addedTokens ) ;
757759 }
758- this . setProperty ( "rangeData" , oEvent . getSource ( ) . getRangeData ( ) ) ;
760+ const aTokens = oEvent . getSource ( ) . getTokens ( ) ;
761+ this . setProperty ( "rangeData" , oEvent . getSource ( ) . getRangeData ( ) . map ( ( oRangeData , iIndex ) => {
762+ oRangeData . tokenText = aTokens [ iIndex ] . getText ( ) ;
763+ return oRangeData ;
764+ } ) ) ;
759765 this . fireChange ( ) ;
760766 } ,
767+ setRangeData ( aRangeData ) {
768+ this . setProperty ( "rangeData" , aRangeData ) ;
769+ this . inputInitialized ( ) . then ( ( input ) => {
770+ input . setRangeData ( aRangeData . map ( ( oRangeData ) => {
771+ const oRangeDataNew = { } ;
772+ Object . entries ( oRangeData ) . forEach ( ( aEntry ) => {
773+ const sKeyNameNew = aEntry [ 0 ] . toLowerCase ( ) ;
774+ oRangeDataNew [ ( sKeyNameNew === "keyfield" ? "keyField" : sKeyNameNew ) ] = aEntry [ 1 ] ;
775+ } ) ;
776+ return oRangeDataNew ;
777+ } ) ) ;
778+ //we need to set token text explicitly, as setRangeData does no recalculation
779+ input . getTokens ( ) . forEach ( ( token , index ) => {
780+ const sTokenText = aRangeData [ index ] . TOKENTEXT ;
781+ if ( sTokenText ) {
782+ token . setText ( sTokenText ) ;
783+ }
784+ } ) ;
785+ } ) ;
786+ } ,
761787 renderer ( oRm , oControl ) { } ,
762788 setControl ( ) {
763789 const input = z2ui5 . oView . byId ( this . getProperty ( "multiInputId" ) ) ;
@@ -769,114 +795,134 @@ sap.ui.define("z2ui5/SmartMultiInputExt", ["sap/ui/core/Control", "sap/m/Token",
769795 }
770796 this . setProperty ( "checkInit" , true ) ;
771797 input . attachTokenUpdate ( this . onTokenUpdate . bind ( this ) ) ;
798+ input . attachInnerControlsCreated ( this . onInnerControlsCreated . bind ( this ) ) ;
799+ } ,
800+ inputInitialized ( input ) {
801+ return new Promise ( ( resolve , reject ) => {
802+ if ( this . _bInnerControlsCreated ) {
803+ resolve ( input ) ; //resolve immediately
804+ } else {
805+ this . _oPendingInnerControlsCreated = resolve ; //resolve later
806+ }
807+ } ) ;
808+ } ,
809+ _oPendingInnerControlsCreated : null ,
810+ _bInnerControlsCreated : false ,
811+ onInnerControlsCreated ( oEvent ) {
812+ const input = oEvent . getSource ( ) ;
813+ if ( this . _oPendingInnerControlsCreated ) {
814+ this . _oPendingInnerControlsCreated ( input ) ;
815+ }
816+ this . _oPendingInnerControlsCreated = null ;
817+ this . _bInnerControlsCreated = true ;
772818 }
773819 } ) ;
774820}
775821) ;
776822
777- sap . ui . define ( "z2ui5/CameraPicture" , [
823+ sap . ui . define ( "z2ui5/CameraPicture" , [
778824 "sap/ui/core/Control" ,
779825 "sap/m/Dialog" ,
780826 "sap/m/Button"
781827] , function ( Control , Dialog , Button ) {
782828 "use strict" ;
783829 return Control . extend ( "z2ui5.CameraPicture" , {
784- metadata : {
785- properties : {
786- id : { type : "string" } ,
787- value : { type : "string" } ,
788- press : { type : "string" } ,
789- autoplay : { type : "boolean" , defaultValue : true }
790- } ,
791- events : {
792- "OnPhoto" : {
793- allowPreventDefault : true ,
794- parameters : {
795- "photo" : {
796- type : "string"
797- }
798- }
799- }
800- } ,
830+ metadata : {
831+ properties : {
832+ id : { type : "string" } ,
833+ value : { type : "string" } ,
834+ press : { type : "string" } ,
835+ autoplay : { type : "boolean" , defaultValue : true }
801836 } ,
802-
803- capture : function ( oEvent ) {
804-
805- var video = document . querySelector ( "#zvideo" ) ;
806- var canvas = document . getElementById ( 'zcanvas' ) ;
807- var resultb64 = "" ;
808- canvas . width = 200 ;
809- canvas . height = 200 ;
810- canvas . getContext ( '2d' ) . drawImage ( video , 0 , 0 , 200 , 200 ) ;
811- resultb64 = canvas . toDataURL ( ) ;
812- this . setProperty ( "value" , resultb64 ) ;
813- this . fireOnPhoto ( {
814- "photo" : resultb64
815- } ) ;
837+ events : {
838+ "OnPhoto" : {
839+ allowPreventDefault : true ,
840+ parameters : {
841+ "photo" : {
842+ type : "string"
843+ }
844+ }
845+ }
816846 } ,
847+ } ,
817848
818- onPicture : function ( oEvent ) {
819-
820- if ( ! this . _oScanDialog ) {
821- this . _oScanDialog = new Dialog ( {
822- title : "Device Photo Function" ,
823- contentWidth : "640px" ,
824- contentHeight : "480px" ,
825- horizontalScrolling : false ,
826- verticalScrolling : false ,
827- stretch : true ,
828- content : [
829- new HTML ( {
830- id : this . getId ( ) + 'PictureContainer' ,
831- content : '<video width="600px" height="400px" autoplay="true" id="zvideo">'
832- } ) ,
833- new Button ( {
834- text : "Capture" ,
835- press : function ( oEvent ) {
836- this . capture ( ) ;
837- this . _oScanDialog . close ( ) ;
838- } . bind ( this )
839- } ) ,
840- new HTML ( {
841- content : '<canvas hidden id="zcanvas" style="overflow:auto"></canvas>'
842- } ) ,
843- ] ,
844- endButton : new Button ( {
845- text : "Cancel" ,
846- press : function ( oEvent ) {
847- this . _oScanDialog . close ( ) ;
848- } . bind ( this )
849- } ) ,
850- } ) ;
851- }
849+ capture : function ( oEvent ) {
850+
851+ var video = document . querySelector ( "#zvideo" ) ;
852+ var canvas = document . getElementById ( 'zcanvas' ) ;
853+ var resultb64 = "" ;
854+ canvas . width = 200 ;
855+ canvas . height = 200 ;
856+ canvas . getContext ( '2d' ) . drawImage ( video , 0 , 0 , 200 , 200 ) ;
857+ resultb64 = canvas . toDataURL ( ) ;
858+ this . setProperty ( "value" , resultb64 ) ;
859+ this . fireOnPhoto ( {
860+ "photo" : resultb64
861+ } ) ;
862+ } ,
852863
853- this . _oScanDialog . open ( ) ;
854-
855- setTimeout ( function ( ) {
856- var video = document . querySelector ( '#zvideo' ) ;
857- if ( navigator . mediaDevices . getUserMedia ) {
858- navigator . mediaDevices . getUserMedia ( { video : { facingMode : { exact : "environment" } } } )
859- . then ( function ( stream ) {
860- video . srcObject = stream ;
861- } )
862- . catch ( function ( error ) {
863- console . log ( "Something went wrong!" ) ;
864- } ) ;
865- }
866- } . bind ( this ) , 300 ) ;
864+ onPicture : function ( oEvent ) {
865+
866+ if ( ! this . _oScanDialog ) {
867+ this . _oScanDialog = new Dialog ( {
868+ title : "Device Photo Function" ,
869+ contentWidth : "640px" ,
870+ contentHeight : "480px" ,
871+ horizontalScrolling : false ,
872+ verticalScrolling : false ,
873+ stretch : true ,
874+ content : [
875+ new HTML ( {
876+ id : this . getId ( ) + 'PictureContainer' ,
877+ content : '<video width="600px" height="400px" autoplay="true" id="zvideo">'
878+ } ) ,
879+ new Button ( {
880+ text : "Capture" ,
881+ press : function ( oEvent ) {
882+ this . capture ( ) ;
883+ this . _oScanDialog . close ( ) ;
884+ } . bind ( this )
885+ } ) ,
886+ new HTML ( {
887+ content : '<canvas hidden id="zcanvas" style="overflow:auto"></canvas>'
888+ } ) ,
889+ ] ,
890+ endButton : new Button ( {
891+ text : "Cancel" ,
892+ press : function ( oEvent ) {
893+ this . _oScanDialog . close ( ) ;
894+ } . bind ( this )
895+ } ) ,
896+ } ) ;
897+ }
867898
868- } ,
899+ this . _oScanDialog . open ( ) ;
900+
901+ setTimeout ( function ( ) {
902+ var video = document . querySelector ( '#zvideo' ) ;
903+ if ( navigator . mediaDevices . getUserMedia ) {
904+ navigator . mediaDevices . getUserMedia ( { video : { facingMode : { exact : "environment" } } } )
905+ . then ( function ( stream ) {
906+ video . srcObject = stream ;
907+ } )
908+ . catch ( function ( error ) {
909+ console . log ( "Something went wrong!" ) ;
910+ } ) ;
911+ }
912+ } . bind ( this ) , 300 ) ;
913+
914+ } ,
869915
870- renderer : function ( oRM , oControl ) {
916+ renderer : function ( oRM , oControl ) {
871917
872- var oButton = new Button ( {
873- icon : "sap-icon://camera" ,
874- text : "Camera" ,
875- press : oControl . onPicture . bind ( oControl ) ,
876- } ) ;
877- oRM . renderControl ( oButton ) ;
918+ var oButton = new Button ( {
919+ icon : "sap-icon://camera" ,
920+ text : "Camera" ,
921+ press : oControl . onPicture . bind ( oControl ) ,
922+ } ) ;
923+ oRM . renderControl ( oButton ) ;
878924
879- } ,
925+ } ,
880926 } ) ;
881927} ) ;
882928
@@ -927,7 +973,7 @@ sap.ui.define("z2ui5/Util", [], () => {
927973 "use strict" ;
928974 return {
929975 DateCreateObject : ( s ) => new Date ( s ) ,
930- // DateAbapTimestampToDate: (sTimestamp) => new sap.gantt.misc.Format.abapTimestampToDate(sTimestamp), commented for UI5 2.x compatibility
976+ // DateAbapTimestampToDate: (sTimestamp) => new sap.gantt.misc.Format.abapTimestampToDate(sTimestamp), commented for UI5 2.x compatibility
931977 DateAbapDateToDateObject : ( d ) => new Date ( d . slice ( 0 , 4 ) , parseInt ( d . slice ( 4 , 6 ) ) - 1 , d . slice ( 6 , 8 ) ) ,
932978 DateAbapDateTimeToDateObject : ( d , t = '000000' ) => new Date ( d . slice ( 0 , 4 ) , parseInt ( d . slice ( 4 , 6 ) ) - 1 , d . slice ( 6 , 8 ) , t . slice ( 0 , 2 ) , t . slice ( 2 , 4 ) , t . slice ( 4 , 6 ) ) ,
933979 } ;
0 commit comments