Skip to content

Commit

Permalink
SVY-10914 Mobile friendly web components
Browse files Browse the repository at this point in the history
  • Loading branch information
gboros committed May 3, 2017
1 parent b91e591 commit 1013b03
Show file tree
Hide file tree
Showing 10 changed files with 213 additions and 58 deletions.
4 changes: 4 additions & 0 deletions META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.4
Created-By: 1.7.0_05-b06 (Oracle Corporation)
CSS-ClientLibs: css/bootstrap/css/bootstrap.css;name=bootstrap;version=3.3.1
JS-ClientLibs: bootstrapcomponents/lib/js/bscomponents-common.js;name=bscomponents-common.js;version=1.0.0,
Bundle-Name: Bootstrap Components
Bundle-SymbolicName: bootstrapcomponents
Bundle-Version: 1.1.2
Expand Down Expand Up @@ -51,3 +52,6 @@ Web-Component: True

Name: formcomponent/formcomponent.spec
Web-Component: True

Name: list/list.spec
Web-Component: True
45 changes: 45 additions & 0 deletions lib/js/bscomponents-common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
angular.module('bootstrapcomponentscommon',['servoy']).filter('showDisplayValue', function () { // filter that takes the realValue as an input and returns the displayValue
return function (input, valuelist) {
var i = 0;
var realValue = input;
if (valuelist) {
if (input && input.hasOwnProperty("realValue")) {
realValue = input.realValue;
}
//TODO performance upgrade: change the valuelist to a hashmap so that this for loop is no longer needed.
//maybe to something like {realValue1:displayValue1, realValue2:displayValue2, ...}
for (i = 0; i < valuelist.length; i++) {
if (realValue === valuelist[i].realValue) {
return getParsedDisplayValue(valuelist[i].displayValue);
}
}
var hasRealValues = false;
for (var i = 0; i < valuelist.length; i++) {
var item = valuelist[i];
if (item.realValue != item.displayValue) {
hasRealValues = true;
break;
}
}
if (hasRealValues) {
var diplayValue = null;
// this then function will resolve right away if the value is already cached on the client.
valuelist.getDisplayValue(realValue).then(function(val){
diplayValue = val;
})
return getParsedDisplayValue(diplayValue);
}
if (valuelist.length == 0) return null;
}

function getParsedDisplayValue(value) {
if (value === undefined || value === null || value === '') {
return '&nbsp;'
} else {
return value;
}
}

return input;
};
});
9 changes: 9 additions & 0 deletions list/list.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.svy-wrapper > * > .bts-list {
width: 100%;
height: 100%;
}

.svy-wrapper > * > .bts-list input {
height: 100%;
padding: 0px 5px;
}
19 changes: 19 additions & 0 deletions list/list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<div class='bts-list'>
<input
svy-enter='handlers.onActionMethodID($event)'
type="text"
list="{{::model.svyMarkupId}}_datalist"
ng-blur='onBlur($event)'
ng-class='model.styleClass'
ng-show='model.visible'
ng-disabled="!model.enabled"
sablo-tabseq='model.tabSeq'
ng-readonly="model.readOnly || !model.editable"
id="{{::model.svyMarkupId}}"/>

<datalist id="{{::model.svyMarkupId}}_datalist">
<option ng-selected="model.dataProviderID === value.realValue" ng-repeat="value in model.valuelistID"
value="{{value.realValue | showDisplayValue:model.valuelistID}}">
</option>
</datalist>
</div>
64 changes: 64 additions & 0 deletions list/list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
angular.module('bootstrapcomponentsList',['servoy', 'bootstrapcomponentscommon']).directive('bootstrapcomponentsList', ['$log', '$sabloConstants', '$filter', '$utils', function($log, $sabloConstants, $filter, $utils) {
return {
restrict: 'E',
scope: {
name: "=",
model: "=svyModel",
handlers: "=svyHandlers",
api: "=svyApi",
svyServoyapi: "="
},
link: function($scope, $element, $attrs) {
var inputEl = $element.find('input');

function updateDataprovider() {
var listValue = inputEl.val();

if($scope.model.valuelistID) {
for (i = 0; i < $scope.model.valuelistID.length; i++) {
if (listValue === $scope.model.valuelistID[i].displayValue) {
listValue = $scope.model.valuelistID[i].realValue;
break;
}
}
}

$scope.model.dataProviderID = listValue;
$scope.svyServoyapi.apply("dataProviderID");
}

inputEl.on("keydown", function(event) {
if($utils.testEnterKey(event)) {
updateDataprovider();
}
});

$scope.$watch('model.dataProviderID', function(newValue, oldValue) {
var listValue = newValue;

if($scope.model.valuelistID) {
var showDisplayValueFilter = $filter("showDisplayValue");
var displayValue = showDisplayValueFilter(listValue, $scope.model.valuelistID);
if(displayValue !== '&nbsp;') {
listValue = displayValue;
}
}

inputEl.val(listValue);
})

$scope.onBlur = function(event) {
updateDataprovider();
}

/**
* Set the focus to the list input
* @example %%prefix%%%%elementName%%.requestFocus();
*/
$scope.api.requestFocus = function() {
inputEl[0].focus();
}
},
templateUrl: 'bootstrapcomponents/list/list.html'
};
}]);
57 changes: 57 additions & 0 deletions list/list.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"name": "bootstrapcomponents-list",
"displayName": "Data List",
"version": 1,
"icon": "servoydefault/typeahead/bhdropdownlisticon.gif",
"definition": "bootstrapcomponents/list/list.js",
"libraries": [{"name":"bootstrapcomponents-list-css", "version":"1.0", "url":"bootstrapcomponents/list/list.css", "mimetype":"text/css"}],
"model":
{
"dataProviderID" : { "type":"dataprovider","pushToServer": "allow", "tags": { "scope" :"design" }, "ondatachange": { "onchange":"onDataChangeMethodID", "callback":"onDataChangeCallback"}},
"enabled" : { "type": "enabled", "blockingOn": false, "default": true, "for": ["dataProviderID","onActionMethodID","onDataChangeMethodID"] },
"readOnly" : { "type": "protected", "blockingOn": true, "default": false,"for": ["dataProviderID","onDataChangeMethodID"], "tags": {"scope":"runtime"} },
"editable" : { "type": "protected", "blockingOn": false, "default": true,"for": ["dataProviderID","onDataChangeMethodID"] },
"styleClass" : { "type" :"styleclass", "tags": { "scope" :"design" }, "default" : "form-control"},
"valuelistID" : { "type" : "valuelist", "tags": { "scope" :"design" }, "for": "dataProviderID"},
"tabSeq" : {"type" :"tabseq", "tags": { "scope" :"design" }},
"visible" : "visible"
},
"handlers":
{
"onActionMethodID" : {

"parameters":[
{
"name":"event",
"type":"JSEvent"
}
]
},
"onDataChangeMethodID" : {
"returns": "boolean",

"parameters":[
{
"name":"oldValue",
"type":"${dataproviderType}"
},
{
"name":"newValue",
"type":"${dataproviderType}"
},
{
"name":"event",
"type":"JSEvent"
}
]
}
},
"api":
{
"requestFocus": {
"delayUntilFormLoads": true,
"discardPreviouslyQueuedSimilarCalls": true
}
}

}
51 changes: 3 additions & 48 deletions select/select.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
angular.module('bootstrapcomponentsSelect',['servoy']).directive('bootstrapcomponentsSelect', ['$log', '$sabloConstants', function($log, $sabloConstants) {
angular.module('bootstrapcomponentsSelect',['servoy', 'bootstrapcomponentscommon']).directive('bootstrapcomponentsSelect', ['$log', '$sabloConstants', function($log, $sabloConstants) {
return {
restrict: 'E',
scope: {
Expand Down Expand Up @@ -42,7 +42,7 @@ angular.module('bootstrapcomponentsSelect',['servoy']).directive('bootstrapcompo
var value = $element.find('select').val();
$scope.model.dataProviderID = value;
$scope.svyServoyapi.apply("dataProviderID");
$scope.handlers.onActionMethodID(event);
if($scope.handlers.onActionMethodID) $scope.handlers.onActionMethodID(event);
}

/**
Expand All @@ -55,49 +55,4 @@ angular.module('bootstrapcomponentsSelect',['servoy']).directive('bootstrapcompo
},
templateUrl: 'bootstrapcomponents/select/select.html'
};
}])
.filter('showDisplayValue', function () { // filter that takes the realValue as an input and returns the displayValue
return function (input, valuelist) {
var i = 0;
var realValue = input;
if (valuelist) {
if (input && input.hasOwnProperty("realValue")) {
realValue = input.realValue;
}
//TODO performance upgrade: change the valuelist to a hashmap so that this for loop is no longer needed.
//maybe to something like {realValue1:displayValue1, realValue2:displayValue2, ...}
for (i = 0; i < valuelist.length; i++) {
if (realValue === valuelist[i].realValue) {
return getParsedDisplayValue(valuelist[i].displayValue);
}
}
var hasRealValues = false;
for (var i = 0; i < valuelist.length; i++) {
var item = valuelist[i];
if (item.realValue != item.displayValue) {
hasRealValues = true;
break;
}
}
if (hasRealValues) {
var diplayValue = null;
// this then function will resolve right away if the value is already cached on the client.
valuelist.getDisplayValue(realValue).then(function(val){
diplayValue = val;
})
return getParsedDisplayValue(diplayValue);
}
if (valuelist.length == 0) return null;
}

function getParsedDisplayValue(value) {
if (value === undefined || value === null || value === '') {
return '&nbsp;'
} else {
return value;
}
}

return input;
};
});
}]);
2 changes: 1 addition & 1 deletion select/select.spec
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"dataProviderID" : { "type":"dataprovider","pushToServer": "allow", "tags": { "scope" :"design" }, "ondatachange": { "onchange":"onDataChangeMethodID", "callback":"onDataChangeCallback"}},
"enabled" : { "type": "enabled", "blockingOn": false, "default": true, "for": ["dataProviderID","onActionMethodID","onDataChangeMethodID"] },
"readOnly" : { "type": "protected", "blockingOn": true, "default": false,"for": ["dataProviderID","onDataChangeMethodID"], "tags": {"scope":"runtime"} },
"styleClass" : { "type" :"styleclass", "tags": { "scope" :"design" }},
"styleClass" : { "type" :"styleclass", "tags": { "scope" :"design" }, "default" : "form-control"},
"valuelistID" : { "type" : "valuelist", "tags": { "scope" :"design" }, "for": "dataProviderID"},
"tabSeq" : {"type" :"tabseq", "tags": { "scope" :"design" }},
"visible" : "visible"
Expand Down
18 changes: 10 additions & 8 deletions textbox/textbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ angular.module('bootstrapcomponentsTextbox',['servoy']).directive('bootstrapcomp
var child = $element.children();
var ngModel = child.controller("ngModel");

$scope.$watch('model.format', function(){
if ($scope.model.format)
{
if (formatState)
formatState(value);
else formatState = $formatterUtils.createFormatState($element, $scope, ngModel,true,$scope.model.format);
}
})
if($scope.model.inputType == "text") {
$scope.$watch('model.format', function(){
if ($scope.model.format)
{
if (formatState)
formatState(value);
else formatState = $formatterUtils.createFormatState($element, $scope, ngModel,true,$scope.model.format);
}
})
}

/**
* Request the focus to this text field.
Expand Down
2 changes: 1 addition & 1 deletion textbox/textbox.spec
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"dataProviderID" : { "type":"dataprovider", "pushToServer": "allow","tags": { "scope" :"design" }, "ondatachange": { "onchange":"onDataChangeMethodID", "callback":"onDataChangeCallback"}},
"enabled" : { "type": "enabled", "blockingOn": false, "default": true, "for": ["dataProviderID","onActionMethodID","onDataChangeMethodID","onFocusGainedMethodID","onFocusLostMethodID","onRightClickMethodID"] },
"format" : {"for":["dataProviderID"] , "type" :"format"},
"inputType" : {"type":"string" , "tags": { "scope" :"design" }, "default" : "text", "values" :["text", "password"]},
"inputType" : {"type":"string" , "tags": { "scope" :"design" }, "default" : "text", "values" :["text", "password", "email", "tel", "date", "time", "datetime-local", "month", "week", "number", "color"]},
"readOnly" : { "type": "protected", "blockingOn": true, "default": false,"for": ["dataProviderID","onDataChangeMethodID"], "tags": {"scope":"runtime"} },
"editable" : { "type": "protected", "blockingOn": false, "default": true,"for": ["dataProviderID","onDataChangeMethodID"] },
"placeholderText" : "tagstring",
Expand Down

0 comments on commit 1013b03

Please sign in to comment.