updates boolean and check box list to use onValueChanged to detect any server value changes.

This commit is contained in:
Shannon
2013-10-01 14:16:57 +10:00
parent e5c7a35e8f
commit e27a0e2bd2
2 changed files with 41 additions and 17 deletions

View File

@@ -1,14 +1,26 @@
function booleanEditorController($scope, $rootScope, assetsService) {
$scope.renderModel = {
value: false
};
if ($scope.model && $scope.model.value && ($scope.model.value.toString() === "1" || angular.lowercase($scope.model.value) === "true")) {
$scope.renderModel.value = true;
function setupViewModel() {
$scope.renderModel = {
value: false
};
if ($scope.model && $scope.model.value && ($scope.model.value.toString() === "1" || angular.lowercase($scope.model.value) === "true")) {
$scope.renderModel.value = true;
}
}
setupViewModel();
$scope.$watch("renderModel.value", function (newVal) {
$scope.model.value = newVal === true ? "1" : "0";
});
//here we declare a special method which will be called whenever the value has changed from the server
//this is instead of doing a watch on the model.value = faster
$scope.model.onValueChanged = function (newVal, oldVal) {
//update the display val again if it has changed from the server
setupViewModel();
};
}
angular.module("umbraco").controller("Umbraco.Editors.BooleanController", booleanEditorController);

View File

@@ -1,22 +1,27 @@
angular.module("umbraco").controller("Umbraco.Editors.CheckboxListController",
function($scope) {
$scope.selectedItems = [];
if (!angular.isObject($scope.model.config.items)) {
throw "The model.config.items property must be either a dictionary";
}
//now we need to check if the value is null/undefined, if it is we need to set it to "" so that any value that is set
// to "" gets selected by default
if ($scope.model.value === null || $scope.model.value === undefined) {
$scope.model.value = [];
function setupViewModel() {
$scope.selectedItems = [];
//now we need to check if the value is null/undefined, if it is we need to set it to "" so that any value that is set
// to "" gets selected by default
if ($scope.model.value === null || $scope.model.value === undefined) {
$scope.model.value = [];
}
for (var i in $scope.model.config.items) {
var isChecked = _.contains($scope.model.value, i);
$scope.selectedItems.push({ checked: isChecked, key: i, val: $scope.model.config.items[i] });
}
}
for (var i in $scope.model.config.items) {
var isChecked = _.contains($scope.model.value, i);
$scope.selectedItems.push({ checked: isChecked, key: i, val: $scope.model.config.items[i] });
}
setupViewModel();
//update the model when the items checked changes
$scope.$watch("selectedItems", function(newVal, oldVal) {
@@ -29,5 +34,12 @@ angular.module("umbraco").controller("Umbraco.Editors.CheckboxListController",
}
}, true);
//here we declare a special method which will be called whenever the value has changed from the server
//this is instead of doing a watch on the model.value = faster
$scope.model.onValueChanged = function (newVal, oldVal) {
//update the display val again if it has changed from the server
setupViewModel();
};
});