Commit ee23a6e8 authored by Evren Kutar's avatar Evren Kutar

submit fix form

bower json dependencies
parent 31af5bec
......@@ -12,7 +12,7 @@ var staff = angular.module('zaerp.staff', ['ngRoute', 'schemaForm', 'formService
/**
* StaffCtrl is a controller
* StaffAddEditCtrl is a controller
* which provide a form with form generator.
*/
......@@ -40,6 +40,7 @@ var staff = angular.module('zaerp.staff', ['ngRoute', 'schemaForm', 'formService
//});
staff.controller('StaffAddEditCtrl', function ($scope, $http, $log, Generator, $routeParams) {
$scope.url = 'personel_duzenle_basitlestirilmis';
var form_params = {};
if ($routeParams.id){
form_params['id'] = $routeParams.id;
......@@ -48,11 +49,11 @@ staff.controller('StaffAddEditCtrl', function ($scope, $http, $log, Generator, $
else {
form_params['cmd'] = 'add_object';
}
Generator.get_form('personel_duzenle_basitlestirilmis', form_params).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;
$scope.form.push({"key": "birth_date", "format": "yyyy-mm-dd"});
//$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);
......@@ -68,17 +69,20 @@ staff.controller('StaffAddEditCtrl', function ($scope, $http, $log, Generator, $
$scope.onSubmit = function (form) {
$scope.$broadcast('schemaFormValidate');
if (form.$valid) {
Generator.submit('edit_staff', $scope);
Generator.submit($scope);
}
}
});
// todo: for single point of failure code a "get item" service and use it to
// retrieve list and single item
/**
* Staff List Controller
*/
staff.controller('StaffListCtrl', function($scope, $http){
$http.get('personel_duzenle_basitlestirilmis').then(function(res){
$http.post('personel_duzenle_basitlestirilmis').then(function(res){
$scope.staffs = res.data;
})
});
......@@ -87,7 +91,7 @@ staff.controller('StaffListCtrl', function($scope, $http){
* Staff Show Controller
*/
staff.controller('StaffShowCtrl', function($scope, $http, $routeParams){
$http.get('http://127.0.0.1:3000/api/list_staff/').then(function(res){
$http.post('personel_duzenle_basitlestirilmis').then(function(res){
$scope.staff = res.data[0];
})
});
\ No newline at end of file
......@@ -42,10 +42,10 @@ form_generator.factory('Generator', function ($http, $q, $log, $timeout, RESTURL
return deferred.promise;
}
};
generator.submit = function (url, $scope) {
generator.submit = function ($scope) {
var get_diff = FormDiff.get_diff($scope.model,$scope.initialModel);
$log.info(get_diff);
$http.post(RESTURL.url + url, get_diff).then(function (res) {
$http.post(RESTURL.url + $scope.url, get_diff).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);
......
......@@ -25,13 +25,11 @@ app.config(['$httpProvider', function ($httpProvider) {
//Will only be called for HTTP up to 300
if(response.data.is_login){
$rootScope.loggedInUser = response.data.is_login;
console.log("login", response.data.is_login);
$location.path("/dashboard");
//$location.path("/dashboard");
}
if(response.screen) {
$location.path(response.screen);
if(response.data.screen) {
$location.path(response.data.screen);
}
console.log("login", response);
return response;
},
'responseError': function (rejection) {
......@@ -40,7 +38,11 @@ app.config(['$httpProvider', function ($httpProvider) {
$location.reload();
}
if(rejection.status === 401) {
$location.path('/login');
if($location.path()==="/login"){
console.log("show errors on login form");
} else{
$location.path('/login');
}
}
return $q.reject(rejection);
}
......
......@@ -6,7 +6,7 @@
"license": "GPL",
"private": false,
"dependencies": {
"angular": "1.4.x",
"angular": "1.4.1",
"angular-mocks": "1.4.x",
"angular-route": "1.4.x",
"angular-resource": "1.4.x",
......
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