Skip to content

Instantly share code, notes, and snippets.

@Adamwaheed
Created March 6, 2015 13:17
Show Gist options
  • Save Adamwaheed/c770c863f4ab47d56b06 to your computer and use it in GitHub Desktop.
Save Adamwaheed/c770c863f4ab47d56b06 to your computer and use it in GitHub Desktop.
'use strict';
angular.module('clientApp')
.controller('staffCtrl', function ($scope,$http,uri,Helper) {
$scope.frm = {};
$scope.deparments = [];
$http.get(uri+'staff').
success(function(data, status, headers, config) {
$scope.staff = data.staff;
$scope.departments = data.departments;
});
$scope.save = function(){
$http.post(uri+'staff/store',$scope.frm).
success(function(data, status, headers, config) {
$scope.frm = {};
$scope.staff = data.staff;
$scope.departments = data.departments;
});
};
$scope.edit = function(edit){
$scope.frm = edit;
var index = Helper.select($scope.departments,edit.department_id);
$scope.frm.department = $scope.departments[index];
};
$scope.delete = function(id){
$http.get(uri+'staff/delete?id='+id.id).
success(function(data, status, headers, config) {
if(angular.isObject(data)){
$scope.deparments = data;
$scope.msg = null;
}else{
$scope.msg = data;
}
});
};
});
angular.module('clientApp').config(function ($stateProvider,$routeProvider,$urlRouterProvider) {
$stateProvider
.state('admin.staff', {
url: '/staff',
templateUrl: 'views/staff/index.html',
controller:'staffCtrl'
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment