Lemonldap-NG-Manager

 view release on metacpan or  search on metacpan

site/htdocs/static/js/notifications.js  view on Meta::CPAN

  // and does not return "null", a level is added. See
  // "$scope.updateTree" method
  overScheme = function (v, level, over) {
    // "v.length > over" avoids a loop if one user opened more than "max"
    // notifications
    console.debug('overScheme => level', level, 'over', over);
    if (level === 1 && v.length > over) {
      return `uid=${v}*&groupBy=substr(uid,${level + over + 1})`;
    } else {
      return null;
    }
  };

  // Session menu
  menu = {
    actives: [{
      title: 'markAsDone',
      icon: 'check'
    }],
    done: [{
      title: 'deleteNotification',
      icon: 'trash'
    }],
    new: [{
      title: 'save',
      icon: 'save'
    }],
    home: []
  };

  // AngularJS application
  llapp = angular.module('llngNotificationsExplorer', ['ui.tree', 'ui.bootstrap', 'llApp']);

  // Main controller
  llapp.controller('NotificationsExplorerCtrl', ['$scope', '$translator', '$location', '$q', '$http', '$uibModal', function ($scope, $translator, $location, $q, $http, $uibModal) {
    var autoId, c, dateToString;
    $scope.links = links;
    $scope.menulinks = menulinks;
    $scope.staticPrefix = staticPrefix;
    $scope.scriptname = scriptname;
    $scope.formPrefix = formPrefix;
    $scope.availableLanguages = availableLanguages;
    $scope.waiting = true;
    $scope.showM = false;
    $scope.showT = true;
    $scope.showForm = false;
    $scope.data = [];
    $scope.form = {};
    $scope.formPost = {};
    $scope.currentScope = null;
    $scope.currentNotification = null;
    $scope.menu = menu;
    // Import translation functions
    $scope.translateP = $translator.translateP;
    $scope.translate = $translator.translate;
    $scope.translateTitle = function (node) {
      return $translator.translateField(node, 'title');
    };
    // Handler menu items
    $scope.menuClick = function (button) {
      if (button.popup) {
        window.open(button.popup);
      } else {
        button.action || (button.action = button.title);
        switch (typeof button.action) {
          case 'function':
            button.action($scope.currentNode, $scope);
            break;
          case 'string':
            $scope[button.action]();
            break;
          default:
            console.warn('Unknown action type', typeof button.action);
        }
      }
      return $scope.showM = false;
    };
    // Notification management
    $scope.markAsDone = function () {
      $scope.waiting = true;
      return $http.put(`${scriptname}notifications/${$scope.type}/${$scope.currentNotification.uid}_${$scope.currentNotification.reference}`, {
        done: 1
      }).then(function (response) {
        $scope.currentNotification = null;
        $scope.currentScope.remove();
        $scope.message = {
          title: 'notificationDeleted'
        };
        $scope.showModal("alert.html");
        $scope.waiting = false;
        return $scope.init();
      }, function (response) {
        $scope.message = {
          title: 'notificationNotDeleted',
          message: response.statusText
        };
        $scope.showModal("alert.html");
        $scope.waiting = false;
        return $scope.init();
      });
    };
    $scope.deleteNotification = function () {
      $scope.waiting = true;
      return $http['delete'](`${scriptname}notifications/${$scope.type}/${$scope.currentNotification.uid}_${$scope.currentNotification.reference}_${$scope.currentNotification.done}`).then(function (response) {
        $scope.currentNotification = null;
        $scope.currentScope.remove();
        $scope.message = {
          title: 'notificationPurged'
        };
        $scope.showModal("alert.html");
        $scope.waiting = false;
        return $scope.init();
      }, function (response) {
        $scope.message = {
          title: 'notificationNotPurged',
          message: response.statusText
        };
        $scope.showModal("alert.html");
        $scope.waiting = false;
        return $scope.init();
      });
    };

site/htdocs/static/js/notifications.js  view on Meta::CPAN

          $scope.showModal("alert.html");
          $scope.waiting = false;
          return $scope.form.date = new Date();
        }, function (response) {
          $scope.message = {
            title: 'notificationNotCreated',
            message: response.statusText
          };
          $scope.showModal("alert.html");
          $scope.waiting = false;
          return $scope.form.date = new Date();
        });
      } else {
        $scope.message = {
          title: 'incompleteForm'
        };
        $scope.showModal("alert.html");
      }
      return $scope.form.date = new Date();
    };
    $scope.init = function () {
      $scope.waiting = true;
      $scope.showM = false;
      $scope.showT = false;
      $scope.data = [];
      $scope.currentScope = null;
      $scope.currentNotification = null;
      $q.all([$translator.init($scope.lang), $scope.updateTree('', $scope.data, 0, 0)]).then(function () {
        return $scope.waiting = false;
      }, function (resp) {
        return $scope.waiting = false;
      });
      // Colorized link
      $scope.activeModule = "notifications";
      return $scope.myStyle = {
        color: '#ffb84d'
      };
    };
    $scope.displayCreateForm = function () {
      $scope.activesStyle = {
        color: '#777'
      };
      $scope.doneStyle = {
        color: '#777'
      };
      $scope.newStyle = {
        color: '#333'
      };
      $scope.waiting = true;
      return $translator.init($scope.lang).then(function () {
        $scope.currentNotification = null;
        $scope.showForm = true;
        $scope.data = [];
        $scope.waiting = false;
        return $scope.form.date = new Date();
      });
    };
    c = $location.path().match(/^\/(\w+)/);
    $scope.type = c ? c[1] : 'actives';
    // Datepicker
    $scope.popupopen = function () {
      return $scope.popup.opened = true;
    };
    $scope.dateOptions = {
      startingDay: 1,
      minDate: new Date()
    };
    $scope.popup = {
      opened: false
    };
    // Date conversion
    return dateToString = function (dt) {
      var day, month, year;
      year = dt.getFullYear();
      month = dt.getMonth() + 1;
      if (month < 10) {
        month = `0${month}`;
      }
      day = dt.getDate();
      if (day < 10) {
        day = `0${day}`;
      }
      return `${year}-${month}-${day}`;
    };
  }]);

})();



( run in 0.672 second using v1.01-cache-2.11-cpan-364913b4093 )