SHARE
TWEET

Checkbox list Javascript controller

a guest Nov 7th, 2016 192 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. angular.module('umbraco').controller('tea.icon-select-list.controller', function ($scope, $http, $routeParams, assetsService, contentResource, notificationsService) {
  2.  
  3.   assetsService.loadCss('/App_Plugins/tea.grid-settings/styles.css');
  4.  
  5.   $scope.items = $scope.model.defaultConfig ? $scope.model.defaultConfig.items : $scope.model.config.items;
  6.  
  7.   if ($scope.model.value) {
  8.     var values = $scope.model.value.split(' ');
  9.     for (var y = 0; y < values.length; y++) {
  10.       for (var i = 0; i < $scope.items.length; i++) {
  11.         if (!$scope.items[i].selected) {
  12.           $scope.items[i].selected = $scope.items[i].value === values[y];
  13.         }
  14.       }
  15.     }
  16.   }
  17.  
  18.   $scope.select = function (item) {
  19.     if ($scope.model.defaultConfig.selectMultiple) {
  20.       item.selected = !item.selected;
  21.     } else {
  22.       if (!item.selected) {
  23.         for (var i = 0; i < $scope.items.length; i++) {
  24.           $scope.items[i].selected = false;
  25.         }
  26.         item.selected = true;
  27.       } else {
  28.         item.selected = false;
  29.       }
  30.     }
  31.     $scope.setValue();
  32.   };
  33.  
  34.   $scope.setValue = function () {
  35.     $scope.model.value = '';
  36.     for (var i = 0; i < $scope.items.length; i++) {
  37.       if ($scope.items[i].selected) {
  38.         $scope.model.value += $scope.items[i].value + ' ';
  39.       }
  40.     }
  41.   };
  42. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top