Skip to content

Instantly share code, notes, and snippets.

@SirajGadhia
Created November 23, 2015 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SirajGadhia/a32ff0352bf16b3ff19c to your computer and use it in GitHub Desktop.
Save SirajGadhia/a32ff0352bf16b3ff19c to your computer and use it in GitHub Desktop.
AngularJS Controller Module (for Courses Admin Modals) - www.Siraj360.com/ng/
//http://www.siraj360.com/ng/ :: A sample single page application (SPA) developed with AngularJS 1.4.5 and Bootstrap 3.3.5.
(function () {
//debugger;
"use strict;"
// 1 - Delete Course
angular.module('FD360').controller('ModalDeleteCourseController',
['$scope', '$modalInstance', 'NoticeAndLogFactory', 'delete_course', ModalDeleteCourseController]);
function ModalDeleteCourseController($scope, $modalInstance, NoticeAndLogFactory, delete_course) {
//debugger;
$scope.deleteCourse = delete_course
$scope.isDelete = (delete_course.Employees.length == 0);
$scope.delete = function () {
$modalInstance.close($scope.deleteCourse);
NoticeAndLogFactory.success("Course " + $scope.deleteCourse.Name + " deleted successfully", "Success", "Delete Course");
};
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
}
// 2 - Edit Course
angular.module('FD360').controller('ModalEditCourseController',
['$scope', '$modalInstance', 'NoticeAndLogFactory', 'edit_course', ModalEditCourseController]);
function ModalEditCourseController($scope, $modalInstance, NoticeAndLogFactory, edit_course) {
// debugger;
$scope.editCourse = edit_course;
$scope.submitFailed = false;
$scope.update = function () {
if ($scope.editCourseForm.$valid) {
$modalInstance.close($scope.editCourse);
NoticeAndLogFactory.success("Edit Course " + $scope.editCourse.Name + " updated successfully", "Success", "Edit Course");
}
else {
$scope.submitFailed = true;
NoticeAndLogFactory.error("Submission failed! Please correct error.", "Error!", "Submission failed! Please correct error.");
}
};
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
}
// 3 - Add Course
angular.module('FD360').controller('ModalAddCourseController',
['$scope', '$modalInstance', 'NoticeAndLogFactory', 'new_course', ModalAddCourseController]);
function ModalAddCourseController($scope, $modalInstance, NoticeAndLogFactory, new_course) {
//debugger;
$scope.newCourse = new_course;
$scope.submitFailed = false;
$scope.save = function () {
if ($scope.addCourseForm.$valid)
{
$modalInstance.close($scope.newCourse);
NoticeAndLogFactory.success("New Course " + $scope.newCourse.Name + " added successfully", "Success", "New Course");
}
else {
$scope.submitFailed = true;
NoticeAndLogFactory.error("Submission failed! Please correct error.", "Error!", "Submission failed! Please correct error.");
}
};
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
}
})();
//Download of full application at https://github.com/SirajGadhia/FD360-V2-AngularJS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment