var formApp = angular.module("formApp", []); formApp.controller('nsFormController', ['$scope', '$http', function($scope, $http){ var formType = $("#nsFormType").attr("class"); $scope.nsForm = {}; if(formType != null){ $scope.getBlank = function(){ $http.get("/api/form/" + formType, {}).then(function(data){ $scope.nsForm = data.data; console.log("Blank form: " + angular.toJson($scope.nsForm, true)); }, function(error){ }); } } $scope.getBlank(); $scope.save = function(){ $scope.nsForm.coreId = $("#nsCoreId").attr("class"); $scope.nsForm.reference = window.location.href; console.log("Filled up form: " + angular.toJson($scope.nsForm, true)); $http.post("/api/newsletterform", $scope.nsForm, {}).then( function(data){ $("#ns-message .success").show(); }, function(error){ $("#ns-message .failure").show(); }); } }]); formApp.controller('teamController', ['$scope', '$http', '$filter', function($scope, $http, $filter){ $scope.webHost = "https://www.therealestateconnect.com" $scope.members = []; $scope.members1 = []; $scope.members2 = []; $scope.members3 = []; $scope.memberMatrix2MD; $scope.memberMatrix2XS; $scope.memberMatrix2XSS; $scope.memberMatrix1MD; $scope.memberMatrix1XS; $scope.memberMatrix1XSS; $scope.memberMatrix3MD; $scope.memberMatrix3XSS; $scope.memberMatrix3XS; $scope.getMembers = function(){ console.log("Called."); $http.get("/api/team").then(function(data){ $scope.members = data.data; $scope.members1 = $filter('filter')($scope.members, {custom3:1}); $scope.members2 = $filter('filter')($scope.members, {custom3:2}); $scope.members3 = $filter('filter')($scope.members, {custom3:3}); $scope.members1 = $filter('orderBy')($scope.members1, 'order'); $scope.members2 = $filter('orderBy')($scope.members2, 'order'); $scope.members3 = $filter('orderBy')($scope.members3, 'order'); $scope.memberMatrix1MD = toMatrix($scope.members1, 6); $scope.memberMatrix1XS = toMatrix($scope.members1, 3); $scope.memberMatrix1XSS = toMatrix($scope.members1, 2); $scope.memberMatrix2MD = toMatrix($scope.members2, 6); $scope.memberMatrix2XS = toMatrix($scope.members2, 3); $scope.memberMatrix2XSS = toMatrix($scope.members2, 2); $scope.memberMatrix3MD = toMatrix($scope.members3, 6); $scope.memberMatrix3XS = toMatrix($scope.members3, 3); $scope.memberMatrix3XSS = toMatrix($scope.members3, 2); }, function(error){ console.log("Error!"); }); } function toMatrix(list, elementsPerSubArray) { var matrix = [], i, k; for (i = 0, k = -1; i < list.length; i++) { if (i % elementsPerSubArray === 0) { k++; matrix[k] = []; } matrix[k].push(list[i]); } return matrix; } $scope.getMembers(); }]); /*formApp.directive('teamTable', function() { return{ restrict: 'E', replace: true, templateUrl: "/trec/js/angular/team.table.html", link: function(scope, element, attr){ } }; });*/ formApp.directive('teamTable', function() { return{ restrict: 'E', replace: true, templateUrl: "https://www.therealestateconnect.com/assets/templates/default/js/team.table.html", link: function(scope, element, attr){ } }; });