(function () { 'use strict'; var app = angular.module('folders'); // A controller to create a showcase app.controller('folderCreateModalController', ['$rootScope', '$scope', '$modalInstance', 'common', 'foldersDataContext','itemSummary','folderService', function ($rootScope, $scope, $modalInstance, common, foldersDataContext, itemSummary, folderService) { var getLogFn = common.logger.getLogFn; var logSuccess = getLogFn("itemSummary", "success"); $scope.folder = { name: '', description: '', folderId : null }; $scope.currentFolders = []; $scope.isNameUnique = true; // TODo shud be false $scope.itemSummary = itemSummary; $scope.isEditMode = false; foldersDataContext.getUserFolders().then(function (folders) { $scope.currentFolders = folders; }) // Check that the name of the showcase is unique $scope.checkFolderNameIsUnique = function (name) { $scope.isNameUnique = folderService.checkFolderNameIsUnique($scope.currentFolders, name); } activate(); function activate() { if ($scope.itemSummary !== null && $scope.itemSummary.itemId !== null) { getFolder(); } } function getFolder() { return foldersDataContext.getFolder($scope.itemSummary.itemId).then(function(data) { $scope.folder = data; $scope.isEditMode = true; }); } // Save the new folder $scope.ok = function () { var operation = $scope.isEditMode ? foldersDataContext.updateFolder : foldersDataContext.createFolder; return operation($scope.folder).then(function (result) { logSuccess("Folder " + $scope.isEditMode ? 'Updated!' : 'Created!'); $modalInstance.close(); $rootScope.$broadcast('UpdateItems'); }); }; // Cancel without saving $scope.cancel = function () { $modalInstance.dismiss('cancel'); }; }]); })();