mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-31 10:31:52 +00:00
refactor update/create behaviors
This commit is contained in:
@@ -5,22 +5,19 @@ angular.module('codexen')
|
||||
|
||||
vm.aceModes = aceModes
|
||||
vm.snippet = snippet
|
||||
console.log(snippet)
|
||||
|
||||
vm.submit = function () {
|
||||
console.log('mode: ', vm.snippet.mode)
|
||||
var params = {
|
||||
description: vm.snippet.description,
|
||||
callSign: vm.snippet.callSign,
|
||||
mode: vm.snippet.mode == null ? null : vm.snippet.mode.toLowerCase(),
|
||||
content: vm.snippet.content,
|
||||
tags: angular.isArray(vm.snippet.tags) ? vm.snippet.tags.map(function (tag) { return tag.name }) : []
|
||||
Tags: angular.isArray(vm.snippet.Tags) ? vm.snippet.Tags.map(function (tag) { return tag.name }) : []
|
||||
}
|
||||
|
||||
Snippet.update(vm.snippet._id, params)
|
||||
Snippet.update(vm.snippet.id, params)
|
||||
.success(function (data) {
|
||||
console.log('updated res :', data)
|
||||
$modalInstance.close(data)
|
||||
console.log('snippet created!', data)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -31,12 +28,12 @@ angular.module('codexen')
|
||||
return Tag.findByName(tagName)
|
||||
.success(function (data) {
|
||||
console.log('tags fetched!!', data)
|
||||
vm.tagCandidates = data.tags
|
||||
vm.tagCandidates = data
|
||||
})
|
||||
}
|
||||
vm.transform = function (tagName) {
|
||||
return {
|
||||
_id: 0,
|
||||
id: 0,
|
||||
name: tagName
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ angular.module('codexen')
|
||||
callSign: vm.callSign,
|
||||
mode: vm.mode == null ? null : vm.mode.toLowerCase(),
|
||||
content: vm.content,
|
||||
tags: angular.isArray(vm.tags) ? vm.tags.map(function (tag) { return tag.name }) : []
|
||||
tags: angular.isArray(vm.Tags) ? vm.Tags.map(function (tag) { return tag.name }) : []
|
||||
}
|
||||
|
||||
Snippet.create(params)
|
||||
@@ -27,12 +27,12 @@ angular.module('codexen')
|
||||
return Tag.findByName(tagName)
|
||||
.success(function (data) {
|
||||
console.log('tags fetched!!', data)
|
||||
vm.tagCandidates = data.tags
|
||||
vm.tagCandidates = data
|
||||
})
|
||||
}
|
||||
vm.transform = function (tagName) {
|
||||
return {
|
||||
_id: 0,
|
||||
id: 0,
|
||||
name: tagName
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* global angular */
|
||||
angular.module('codexen')
|
||||
.controller('SnippetsDetailController', function (Snippet, $state, $rootScope) {
|
||||
.controller('SnippetsDetailController', function (Snippet, $state, $rootScope, $scope) {
|
||||
var vm = this
|
||||
|
||||
vm.isLoaded = false
|
||||
@@ -23,4 +23,9 @@ angular.module('codexen')
|
||||
$rootScope.$broadcast('snippetDeleted')
|
||||
})
|
||||
}
|
||||
|
||||
$scope.$on('snippetUpdated', function (e, snippet) {
|
||||
console.log('event received', snippet)
|
||||
if (snippet.id === vm.snippet.id) vm.snippet = snippet
|
||||
})
|
||||
})
|
||||
|
||||
@@ -34,7 +34,7 @@ angular.module('codexen')
|
||||
})
|
||||
|
||||
$scope.$on('snippetUpdated', function (e, snippet) {
|
||||
$state.go('snippets.detail', {id: snippet._id})
|
||||
$state.go('snippets.detail', {id: snippet.id})
|
||||
loadSnippets()
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user