Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var app = angular.module('view', ['ngRoute','ngResource']);
- app.factory('Users',function ($resource) {
- return $resource("api/users/:username");
- });
- app.factory('Projects',function ($resource) {
- return $resource("api/projects");
- });
- app.config(['$qProvider', function ($qProvider) {
- $qProvider.errorOnUnhandledRejections(false);
- }]);
- var iRP = 1;
- app.config(function($routeProvider){
- $routeProvider
- .when('/login', {
- templateUrl:"login/login.html",
- controller:'loginCtrl'})
- .when('/user/:username',{
- templateUrl:'userPanel/userPanel.html',
- controller:'userPanelCtrl'})
- .when('/user/:username/projects',{
- templateUrl:'projects/projects.html',
- controller:'projectsCtrl'})
- .when('/',{
- templateUrl:'registration/registration.html',
- controller:'registrationCtrl'})
- .otherwise({
- redirectTo: '/'});
- });
- app.controller('loginCtrl', function($scope, $location,Users){
- $scope.isProper = 1;
- $scope.message='bad data!';
- $scope.authenticate = function(user){
- var u = Users.get({username : $scope.user.login});
- if(u.pwd == $scope.user.pwd){
- $location.path('/user/'+user.login);
- }
- else{
- $scope.isProper=0;
- $location.path('/login');
- }
- };
- });
- app.controller('projectsCtrl', function($scope,$routeParams, $location, Projects){
- $scope.login=$routeParams.username;
- $scope.p=Projects.query({username : $scope.login});;
- $scope.redirectToData = function(){
- $location.path('/user/'+$routeParams.username);
- };
- $scope.np = new Projects();
- $scope.fetchAllProjects=function () {
- $scope.p = Projects.query({username : $scope.login});
- };
- $scope.addProject = function () {
- $scope.np.owner=$routeParams.username;
- $scope.np.$save(function () {
- $scope.fetchAllProjects();
- });
- $scope.np={};
- };
- $scope.deleteProject = function (project) {
- var project = Projects.get({name:project.name},function () {
- project.$delete(function () {
- $scope.fetchAllProjects();
- });
- });
- };
- });
- app.controller('userPanelCtrl', function($scope, $routeParams, $location, Users) {
- $scope.user=Users.get({username : $routeParams.username});
- $scope.user.reppwd=$scope.user.pwd;
- $scope.redirectToProjects = function () {
- $location.path('/user/' + $routeParams.username + '/projects');
- };
- $scope.deleteUser = function () {
- $scope.user.$delete(function () {
- $location.path('/register');
- });
- };
- });
- app.controller('registrationCtrl', function($scope, $location, $routeParams, Users) {
- $scope.isRegProper = iRP;
- $scope.acc='0';
- $scope.message='bad data!';
- var user = new Users($scope.user);
- $scope.registrationAuth = function(){
- user.$save(function () {
- $location.path('/login');
- });
- };
- $scope.redirect = function(){
- $location.path('/login');
- };
- });
- app.directive("passwordVerify", function() {
- return {
- require: "ngModel",
- scope: {
- passwordVerify: '='
- },
- link: function(scope, element, attrs, ctrl) {
- scope.$watch(function() {
- var combined;
- if (scope.passwordVerify || ctrl.$viewValue) {
- combined = scope.passwordVerify + '_' + ctrl.$viewValue;
- }
- return combined;
- }, function(value) {
- if (value) {
- ctrl.$parsers.unshift(function(viewValue) {
- var origin = scope.passwordVerify;
- if (origin !== viewValue) {
- ctrl.$setValidity("passwordVerify", false);
- return undefined;
- } else {
- ctrl.$setValidity("passwordVerify", true);
- return viewValue;
- }
- });
- }
- });
- }
- };
- });
- app.directive('checkRequired', function(){
- return {
- require: 'ngModel',
- link: function (scope, element, attrs, ngModel) {
- ngModel.$validators.checkRequired = function (modelValue, viewValue) {
- var value = modelValue || viewValue;
- var match = scope.$eval(attrs.ngTrueValue) || true;
- return value && match === value;
- };
- }
- };
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement