Commit c5638776 authored by Evren Kutar's avatar Evren Kutar

add ve edit fonksiyonları ayrıldı.

testve route'lar güncellendi
parent 6d87d7b5
...@@ -68,13 +68,46 @@ app.config(['$routeProvider', function ($routeProvider) { ...@@ -68,13 +68,46 @@ app.config(['$routeProvider', function ($routeProvider) {
}) })
.when('/staff/add', { .when('/staff/add', {
templateUrl: 'components/staff/staff_add_template.html', templateUrl: 'components/staff/staff_add_template.html',
controller: 'StaffAddEditCtrl', controller: 'StaffAddCtrl',
resolve: { resolve: {
loadMyCtrl: ['$ocLazyLoad', function ($ocLazyLoad) { loadMyCtrl: ['$ocLazyLoad', function ($ocLazyLoad) {
return $ocLazyLoad.load('components/staff/staff_controller.js'); return $ocLazyLoad.load('components/staff/staff_controller.js');
}], }],
loadMyService: ['$ocLazyLoad', function ($ocLazyLoad) { loadMyService: ['$ocLazyLoad', function ($ocLazyLoad) {
return $ocLazyLoad.load('zetalib/forms/form_service.js'); return $ocLazyLoad.load('zetalib/forms/form_service.js');
}],
loadMyService2: ['$ocLazyLoad', function ($ocLazyLoad) {
return $ocLazyLoad.load('zetalib/general.js');
}]
}
})
.when('/staff/edit/:id', {
templateUrl: 'components/staff/staff_add_template.html',
controller: 'StudentEditCtrl',
resolve: {
loadMyCtrl: ['$ocLazyLoad', function ($ocLazyLoad) {
return $ocLazyLoad.load('components/student/student_controller.js');
}],
loadMyService: ['$ocLazyLoad', function ($ocLazyLoad) {
return $ocLazyLoad.load('zetalib/forms/form_service.js');
}],
loadMyService2: ['$ocLazyLoad', function ($ocLazyLoad) {
return $ocLazyLoad.load('zetalib/general.js');
}]
}
})
.when('/staffs', {
templateUrl: 'components/staff/staff_list_template.html',
controller: 'StaffListCtrl',
resolve: {
loadMyCtrl: ['$ocLazyLoad', function ($ocLazyLoad) {
return $ocLazyLoad.load('components/student/student_controller.js');
}],
loadMyService: ['$ocLazyLoad', function ($ocLazyLoad) {
return $ocLazyLoad.load('zetalib/forms/form_service.js');
}],
loadMyService2: ['$ocLazyLoad', function ($ocLazyLoad) {
return $ocLazyLoad.load('zetalib/general.js');
}] }]
} }
}) })
......
...@@ -16,8 +16,8 @@ var staff = angular.module('zaerp.staff', ['ngRoute', 'schemaForm', 'formService ...@@ -16,8 +16,8 @@ var staff = angular.module('zaerp.staff', ['ngRoute', 'schemaForm', 'formService
* which provide a form with form generator. * which provide a form with form generator.
*/ */
staff.controller('StaffAddEditCtrl', function ($scope, $http, $log, Generator, $routeParams) { staff.controller('StaffAddCtrl', function ($scope, $http, $log, Generator, $routeParams) {
Generator.get_form('add_staff', $routeParams).then(function (d) { Generator.get_form('add_staff', '').then(function (d) {
$scope.schema = d.schema; $scope.schema = d.schema;
$scope.form = d.form; $scope.form = d.form;
$scope.model = d.model ? d.model : {}; $scope.model = d.model ? d.model : {};
...@@ -28,6 +28,7 @@ staff.controller('StaffAddEditCtrl', function ($scope, $http, $log, Generator, $ ...@@ -28,6 +28,7 @@ staff.controller('StaffAddEditCtrl', function ($scope, $http, $log, Generator, $
title: "Save" title: "Save"
} }
); );
return $scope;
}); });
$scope.onSubmit = function (form) { $scope.onSubmit = function (form) {
$scope.$broadcast('schemaFormValidate'); $scope.$broadcast('schemaFormValidate');
...@@ -36,4 +37,37 @@ staff.controller('StaffAddEditCtrl', function ($scope, $http, $log, Generator, $ ...@@ -36,4 +37,37 @@ staff.controller('StaffAddEditCtrl', function ($scope, $http, $log, Generator, $
$log.info($scope); $log.info($scope);
} }
} }
});
staff.controller('StaffEditCtrl', function ($scope, $http, $log, Generator, $routeParams) {
Generator.get_form('add_staff', $routeParams.id).then(function (d) {
$scope.schema = d.schema;
$scope.form = d.form;
$scope.model = d.model ? 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) {
// todo: implement form diff here
$log.info($scope);
}
}
});
/**
* Staff List Controller
*/
staff.controller('StaffListCtrl', function($scope, $http){
$http.get('http://127.0.0.1:3000/api/list_staff').then(function(res){
$scope.staffs = res.data;
})
}); });
\ No newline at end of file
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
'use strict'; 'use strict';
describe('staff controller module', function () { describe('staff controller module', function () {
beforeEach(module('zaerp'));
beforeEach(module('zaerp.staff')); beforeEach(module('zaerp.staff'));
var $controller; var $controller;
...@@ -16,22 +18,18 @@ describe('staff controller module', function () { ...@@ -16,22 +18,18 @@ describe('staff controller module', function () {
$controller = _$controller_; $controller = _$controller_;
})); }));
//describe('$scope.grade', function() { describe('staff add controller', function() {
// it('', function() { it('should get form', function() {
// var $scope = {}; var $scope = {};
// var controller = $controller('StaffAddEditCtrl', { $scope: $scope }); var controller = $controller('StaffAddCtrl', { $scope: $scope });
// expect($scope).not.toBe(null); expect($scope).not.toEqual(null);
// }); });
//}); });
//
//describe('staff add controller', function () { describe('staff add controller', function () {
//
// it('should have StaffAddEditCtrl', inject(function (ctrl) { it('should have StaffAddEditCtrl', inject(function ($controller) {
// expect(ctrl).toBeDefined(); expect($controller).toBeDefined();
// })); }));
// });
// it('should get form', inject(function () {
// expect($scope.form).not.toBe(null);
// }));
//});
}); });
\ No newline at end of file
<table class="table table-bordered">
<thead>
<tr>
<th ng-repeat="(key,value) in staffs[0]">{{ key }}</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="staff in staffs">
<td ng-repeat="(key,value) in staff">{{value}}</td>
<td><a ng-href="#/s/edit/{{staff.id}}">Edit</a></td>
</tr>
</tbody>
</table>
\ No newline at end of file
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