Skip to content

Instantly share code, notes, and snippets.

@rbaty-barr
Created September 6, 2017 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbaty-barr/846ebae4a438998c873a8f62379707bd to your computer and use it in GitHub Desktop.
Save rbaty-barr/846ebae4a438998c873a8f62379707bd to your computer and use it in GitHub Desktop.
This is a sample of a custom pre-vaule editor that is a checkbox property for the grid
[
{
"label": "Show by state",
"description": "Show this row for the following states.",
"key": "state",
"view": "/App_Plugins/StatePicker/state-picker-list.html",
"applyTo": "row",
"defaultConfig": {
"selectMultiple": true,
"displaySelectInversed": true,
"items": [
{
"text": "Arizona",
"value": "arizona",
"selected": false
},
{
"text": "California",
"value": "california",
"selected": false
},
{
"text": "Colorado",
"value": "colorado",
"selected": false
},
{
"text": "New Mexico West Texas",
"value": "new-mexico-west-texas",
"selected": false
}
]
}
}
]
{
"gridEditors": [
{
"name": "States",
"alias": "states",
"view": "/app_plugins/StatePicker/state-picker-list.html",
"icon": "icon-code",
"config": {
"items": [
{
"text": "Arizona",
"value": "arizona",
"selected": false
},
{
"text": "California",
"value": "california",
"selected": false
},
{
"text": "Colorado",
"value": "colorado",
"selected": false
},
{
"text": "New Mexico West Texas",
"value": "new-mexico-west-texas",
"selected": false
}
]
}
}
],
javascript:[
"/app_plugins/StatePicker/state-picker.controller.js"
]
}
<div ng-controller="state-picker.controller">
<div ng-repeat="item in items" class="checkbox" ng-class="{'displaySelectInversed': model.defaultConfig.displaySelectInversed}">
<label>
<input type="checkbox" value="{{item.value}}" ng-model="item.selected" ng-click="select(item)">
{{item.text}}
</label>
</div>
</div>
angular.module('umbraco').controller('state-picker.controller', function ($scope, $http, $routeParams, assetsService, contentResource, notificationsService) {
assetsService.loadCss('/App_Plugins/StatePicker/styles.css');
$scope.items = $scope.model.defaultConfig ? $scope.model.defaultConfig.items : $scope.model.config.items;
if ($scope.model.value) {
var values = $scope.model.value.split(' ');
for (var y = 0; y < values.length; y++) {
for (var i = 0; i < $scope.items.length; i++) {
if ($scope.items[i].value == values[y]) {
$scope.items[i].selected = true;
}
}
}
}
$scope.select = function (item) {
$scope.setValue();
};
$scope.setValue = function () {
$scope.model.value = '';
for (var i = 0; i < $scope.items.length; i++) {
if ($scope.items[i].selected) {
$scope.model.value += $scope.items[i].value + ' ';
}
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment