Skip to content

Instantly share code, notes, and snippets.

@kis
Created September 9, 2015 12:56
Show Gist options
  • Save kis/b1e78bd116417e189150 to your computer and use it in GitHub Desktop.
Save kis/b1e78bd116417e189150 to your computer and use it in GitHub Desktop.
modal instance
$scope.openModal = function(video) {
var modalInstance = addVideoService.openAddVideoModal(video);
return modalInstance.result;
};
$scope.addVideo = function() {
$scope.openModal(null).then(function(data) {
data.date_created = new Date();
$scope.profile.videos.unshift(data);
});
};
$scope.editVideo = function(video_id, title, url) {
event.stopPropagation();
var video = {title: title, url: url};
$scope.openModal(video).then(function(data) {
$scope.profile.videos.forEach(function(video, index, arr) {
if (video.video_id == video_id) {
if (data.remove) {
arr.splice(index, 1);
} else {
arr[index].title = data.title;
arr[index].url = data.url;
}
}
});
});
};
$scope.removeVideo = function(video_id) {
event.stopPropagation();
if (confirm('Delete video?')) {
$scope.profile.videos.forEach(function(video, index, arr) {
if (video.video_id == video_id) {
arr.splice(index, 1);
}
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment