From 86a407cd3fcbefb16b00ea9ef10bd80f2b0e0a0f Mon Sep 17 00:00:00 2001
From: Roberto Sánchez <roberto.sanchez@curisit.net>
Date: Mon, 30 Dec 2013 17:03:43 +0000
Subject: [PATCH] #333 feature - Added form validation in catalog page
---
securis/src/main/resources/static/js/admin.js | 28 ++++++++++++++++++++++++----
1 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/securis/src/main/resources/static/js/admin.js b/securis/src/main/resources/static/js/admin.js
index 45f2b1b..0000694 100644
--- a/securis/src/main/resources/static/js/admin.js
+++ b/securis/src/main/resources/static/js/admin.js
@@ -3,6 +3,19 @@
var app = angular.module('app', [ 'ngRoute', 'ngAnimate' ]);
+ app.directive('catalogField', function() {
+ return {
+ restrict: 'A', // only activate on element attribute
+ require: '?ngModel', // get a hold of NgModelController
+ link: function(scope, element, attrs, ngModel) {
+ if(!ngModel) return; // do nothing if no ng-model
+ // TODO: Replace the hard-coded form ID by the appropiate dynamic field
+ scope.catalogForm[attrs.name] = scope.catalogForm['{{field.name}}'];
+ scope.catalogForm[attrs.name].$name = attrs.name;
+ }
+ };
+ });
+
app.factory('Catalogs', function($http) {
var CatalogsService = {}
CatalogsService.list = function(initFn) {
@@ -39,25 +52,32 @@
} ]);
- app.controller('CatalogFormCtrl', [ '$scope', '$http',
+ app.controller('CatalogFormCtrl', [ '$scope', '$http', 'Catalogs',
- function($scope, $http, menuController) {
+ function($scope, $http, menuController, Catalogs) {
$scope.showForm = false;
+ $scope.scope = $scope;
console.log('Form: currentCatalog:'+ $scope.cataLogIndex);
$scope.editNew = function() {
$scope.showForm = true;
$scope.isNew = true;
- $scope.formu = {};
+ //$scope.formu = {};
}
$scope.edit = function() {
$scope.showForm = true;
$scope.isNew = false;
// TODO: Load in formu values for Form
- $scope.formu = {};
+ //$scope.formu = {};
}
$scope.cancel = function() {
$scope.showForm = false;
}
+
+ $scope.saveCatalog = function() {
+ if ($scope.catalogForm.$invalid) {
+ alert(JSON.stringify($scope.catalogForm))
+ }
+ }
} ]);
app.controller('CatalogListCtrl', [ '$scope', '$http',
--
Gitblit v1.3.2