Commit 3533ee66 authored by Evren Kutar's avatar Evren Kutar

Merge branch 'backend_implementation'

parents 6c8f81fb 79e6dfb7
......@@ -97,6 +97,7 @@ var app = angular.module(
$rootScope.loggedInUser = false;
console.log($rootScope.loggedInUser);
$location.path("/login");
$scope.$apply();
});
});
}
......
......@@ -167,18 +167,17 @@ app.config(['$routeProvider', function ($routeProvider) {
*
*/
//$rootScope.loggedInUser ? $rootScope.loggedInUser : false;
//$rootScope.$on("$routeChangeStart", function (event, next, current) {
// if ($rootScope.loggedInUser == null) {
// // no logged user, redirect to /login
// console.log($rootScope.loggedInUser);
// if (next.templateUrl === "login/login.html") {
//
// } else {
// $location.path("/login");
// }
// }
//});
$rootScope.loggedInUser ? $rootScope.loggedInUser : false;
$rootScope.$on("$routeChangeStart", function (event, next, current) {
if ($rootScope.loggedInUser == null) {
// no logged user, redirect to /login
if (next.templateUrl === "login/login.html") {
} else {
$location.path("/login");
}
}
});
}).config(['$httpProvider', function($httpProvider) {
// to send cookies CORS
$httpProvider.defaults.withCredentials = true;
......
......@@ -7,94 +7,35 @@
'use strict';
// TODO: clean console log items
// TODO: password hash or not??
// TODO: who field can be removed??
// todo: use zetalib/forms/form_service functions for email validation
var auth = angular.module('zaerp.auth', ['ngRoute', 'schemaForm', 'ngCookies', 'general']);
auth.controller('LoginCtrl', function ($scope, $q, $timeout, $routeParams, Generator, LoginService) {
auth.controller('LoginCtrl', function ($scope, $rootScope, $q, $timeout, $routeParams, Generator, LoginService) {
$scope.url = 'simple_login';
var form_params = {};
if ($rootScope.loginwfclear){
form_params['clear_wf'] = 1;
} else{
$rootScope.loginwfclear = 1
}
// todo: change simple login when api ready
Generator.get_form($scope.url, $routeParams).then(function(data){
Generator.get_form($scope.url, form_params).then(function(data){
var d = data.data.forms;
$scope.schema = d.schema;
$scope.form = d.form;
// model is the init data of the form or in edit templates
$scope.model = d.model ? d.model : {};
$scope.initialModel = angular.copy(d.model);
for (var key in d)
$scope[key] = d[key];
// for email validation add asyncvalidator
//$scope.form[0].$asyncValidators = Generator.asyncValidators;
// add submit button to the form todo: move this to form service
$scope.form.push(
{
type: "submit",
title: "Save"
}
);
//$scope.form.push(
// {
// type: "submit",
// title: "Save"
// }
//);
$scope.form = [
"*",
{ key: "password", type: "password"},
{ type: 'submit', title: 'Save' }
];
});
//$scope.schema =
//{
// title: "Login",
// type: "object",
// properties: {
// email: {
// type: "email",
// title: "Email"
// },
// password: {
// type: "string",
// title: "Password"
// },
// remember: {
// type: "boolean",
// title: "Remember me?"
// },
// who: {
// title: "Who are you?",
// type: "string",
// enum: ["student", "stuff", "dean"]
// }
// },
// required: ["email", "password", "who"]
//};
//$scope.model = {
// email: "user@example.com",
// remember: false
//};
//$scope.form = [
// {
// key: "email",
// type: "email",
// validationMessages: {
// 'emailNotValid': 'Email is not valid!'
// },
// $asyncValidators: {
// emailNotValid: function (value) {
// var deferred = $q.defer();
// $timeout(function () {
// if (LoginService.isValidEmail(value)) {
// deferred.resolve();
// } else {
// deferred.reject();
// }
// }, 500);
// return deferred.promise;
// }
// }
// },
// {
// key: "password",
// type: "password"
// },
// "remember",
// "who",
// {
// type: "submit",
// title: "Save"
// }
//];
$scope.onSubmit = function (form) {
$scope.$broadcast('schemaFormValidate');
if (form.$valid) {
......
......@@ -13,5 +13,4 @@ angular.module('zaerp.dashboard', ['ngRoute'])
.controller('DashCtrl', function ($scope) {
$scope.testData = "<h1>This is main Dashboard</h1>";
console.log(22);
});
\ No newline at end of file
......@@ -16,50 +16,28 @@ var staff = angular.module('zaerp.staff', ['ngRoute', 'schemaForm', 'formService
* which provide a form with form generator.
*/
//staff.controller('StaffAddCtrl', function ($scope, $http, $log, Generator) {
// Generator.get_form('add_staff', '').then(function (d) {
// $scope.schema = d.schema;
// $scope.form = d.form;
// $scope.model = d.model ? d.model : {};
// $scope.initialModel = angular.copy(d.model);
// $scope.form[0].$asyncValidators = Generator.asyncValidators;
// $scope.form.push(
// {
// type: "submit",
// title: "Save"
// }
// );
// return $scope;
// });
// $scope.onSubmit = function (form) {
// $scope.$broadcast('schemaFormValidate');
// if (form.$valid) {
// Generator.submit('add_staff', $scope);
// }
// }
//});
staff.controller('StaffAddEditCtrl', function ($scope, $http, $log, Generator, $routeParams) {
staff.controller('StaffAddEditCtrl', function ($scope, $rootScope, $http, $log, Generator, $routeParams) {
$scope.url = 'personel_duzenle_basitlestirilmis';
var form_params = {};
if ($routeParams.id) {
form_params['id'] = $routeParams.id;
form_params['object_id'] = $routeParams.id;
form_params['cmd'] = 'edit_object';
}
else {
form_params['cmd'] = 'add_object';
}
form_params['clear_wf'] = 1;
if ($rootScope.staffwfclear){
form_params['clear_wf'] = 1;
} else{
$rootScope.staffwfclear = 1
}
Generator.get_form($scope.url, form_params).then(function (data) {
var d = data.data.forms;
console.log(d);
$scope.schema = d.schema;
$scope.form = d.form;
delete $scope.form[0];
//$scope.form.push({"key": "birth_date", "format": "yyyy-mm-dd"});
$scope.model = d.model ? d.model : {};
$scope.initialModel = angular.copy(d.model);
//$scope.form.push($asyncValidators: Generator.asyncValidators);
// add form, schema and model to scope object
for (var key in d)
$scope[key] = d[key];
$scope.initialModel = angular.copy($scope.model);
$scope.form.push(
{
type: "submit",
......@@ -82,17 +60,30 @@ staff.controller('StaffAddEditCtrl', function ($scope, $http, $log, Generator, $
* Staff List Controller
*/
staff.controller('StaffListCtrl', function ($scope, $http, RESTURL) {
$http.post(RESTURL.url + 'personel_duzenle_basitlestirilmis').then(function (res) {
$scope.staffs = res.data;
})
staff.controller('StaffListCtrl', function ($scope, $rootScope, Generator) {
var form_params = {};
if ($rootScope.staffwfclear){
form_params['clear_wf'] = 1;
} else{
$rootScope.staffwfclear = 1
}
Generator.get_form('personel_duzenle_basitlestirilmis', form_params)
.then(function (res) {
$scope.staffs = res.data;
});
});
/**
* Staff Show Controller
*/
staff.controller('StaffShowCtrl', function ($scope, $http, RESTURL, $routeParams) {
$http.post(RESTURL.url + 'personel_duzenle_basitlestirilmis').then(function (res) {
staff.controller('StaffShowCtrl', function ($scope, $rootScope, Generator, $routeParams) {
var form_params = {"object_id": $routeParams.id};
if ($rootScope.staffwfclear){
form_params['clear_wf'] = 1;
} else{
$rootScope.staffwfclear = 1
}
Generator.get_form('personel_duzenle_basitlestirilmis', form_params).then(function (res) {
$scope.staff = res.data[0];
})
});
\ No newline at end of file
......@@ -9,6 +9,9 @@ var form_generator = angular.module('formService', ['general']);
form_generator.factory('Generator', function ($http, $q, $log, $timeout, RESTURL, FormDiff) {
var generator = {};
generator.makeUrl = function(url){
return RESTURL.url + url;
};
generator.generate = function (modelObject) {
return generator.group(modelObject);
};
......@@ -17,11 +20,9 @@ form_generator.factory('Generator', function ($http, $q, $log, $timeout, RESTURL
};
generator.get_form = function (url, getParams) {
return $http
.post(RESTURL.url + url, getParams)
.post(generator.makeUrl(url), getParams)
.success(function (res) {
if (res.status == 200) {
return generator.generate(res.data);
}
return generator.generate(res.data);
// todo: cover all other exceptions (4xx, 5xx)
});
};
......@@ -43,9 +44,14 @@ form_generator.factory('Generator', function ($http, $q, $log, $timeout, RESTURL
}
};
generator.submit = function ($scope) {
var get_diff = FormDiff.get_diff($scope.model,$scope.initialModel);
$log.info(get_diff);
$http.post(RESTURL.url + $scope.url, get_diff).then(function (res) {
if($scope.object_id) {
var get_diff = FormDiff.get_diff($scope.model, $scope.initialModel);
var data = {"object_id": $scope.id, "form": get_diff};
}
else {
data = $scope.model;
}
$http.post(generator.makeUrl($scope.url), data).then(function (res) {
// todo: for now fake rest api returns 'ok' no data to
// manipulate on ui. therefor used just a log
$log.info(res);
......
......@@ -15,7 +15,7 @@ app.config(['$httpProvider', function ($httpProvider) {
'request': function(config){
// todo: delete console logs
if (config.method == "POST"){
console.log("post request")
} else {
}
......@@ -23,9 +23,13 @@ app.config(['$httpProvider', function ($httpProvider) {
},
'response': function (response) {
//Will only be called for HTTP up to 300
if(response.data.is_login){
if(response.data.is_login===true){
$rootScope.loggedInUser = response.data.is_login;
//$location.path("/dashboard");
if($location.path()==="/login"){
$location.path('/dashboard');
} else{
$location.replace();
}
}
if(response.data.screen) {
$location.path(response.data.screen);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment