Created
November 22, 2016 19:03
-
-
Save drichar/0399c24cf9082bc134f3508f1f8088bd to your computer and use it in GitHub Desktop.
Manage sortable lesson slides
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
'use strict'; | |
angular.module('app') | |
.directive('adminSort', adminSort); | |
function adminSort() { | |
var directive = { | |
restrict: 'EA', | |
templateUrl: "/views/admin/adminsort.html", | |
link: linkFunc, | |
controller: AdminSortController, | |
controllerAs: 'vm', | |
bindToController: true | |
}; | |
return directive; | |
function linkFunc(scope, el, attr, ctrl) { | |
var element = document.getElementById(attr.id); | |
var sortable = new Sortable(element, { | |
animation: 250, | |
onUpdate: function (evt) { | |
console.log(evt.oldIndex); | |
console.log(evt.newIndex); | |
} | |
}); | |
} | |
} | |
AdminSortController.$inject = ['LessonsService', '$stateParams']; | |
function AdminSortController(LessonsService, $stateParams) { | |
var vm = this; | |
vm.lesson = {}; | |
vm.lessonId = $stateParams.lessonId; | |
vm.getLesson = getLesson; | |
vm.testFunc = testFunc; | |
activate(); | |
function activate() { | |
return getLesson().then(function() { | |
Materialize.toast("<i class='material-icons md-36 teal-text text-lighten-1'>check_circle</i> Lesson loaded", 3000); | |
}); | |
} | |
function getLesson() { | |
return LessonsService.getLesson(vm.lessonId).then(function(data) { | |
vm.lesson = data; | |
return vm.lesson; | |
}); | |
} | |
function testFunc() { | |
console.log("Invoked"); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment