1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-15 02:36:36 +00:00

refactor update/create behaviors

This commit is contained in:
Rokt33r
2015-06-10 02:36:07 +09:00
parent f1adb9783b
commit 68956ec360
7 changed files with 17 additions and 19 deletions

View File

@@ -5,22 +5,19 @@ angular.module('codexen')
vm.aceModes = aceModes vm.aceModes = aceModes
vm.snippet = snippet vm.snippet = snippet
console.log(snippet)
vm.submit = function () { vm.submit = function () {
console.log('mode: ', vm.snippet.mode)
var params = { var params = {
description: vm.snippet.description, description: vm.snippet.description,
callSign: vm.snippet.callSign, callSign: vm.snippet.callSign,
mode: vm.snippet.mode == null ? null : vm.snippet.mode.toLowerCase(), mode: vm.snippet.mode == null ? null : vm.snippet.mode.toLowerCase(),
content: vm.snippet.content, 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) { .success(function (data) {
console.log('updated res :', data)
$modalInstance.close(data) $modalInstance.close(data)
console.log('snippet created!', data)
}) })
} }
@@ -31,12 +28,12 @@ angular.module('codexen')
return Tag.findByName(tagName) return Tag.findByName(tagName)
.success(function (data) { .success(function (data) {
console.log('tags fetched!!', data) console.log('tags fetched!!', data)
vm.tagCandidates = data.tags vm.tagCandidates = data
}) })
} }
vm.transform = function (tagName) { vm.transform = function (tagName) {
return { return {
_id: 0, id: 0,
name: tagName name: tagName
} }
} }

View File

@@ -11,7 +11,7 @@ angular.module('codexen')
callSign: vm.callSign, callSign: vm.callSign,
mode: vm.mode == null ? null : vm.mode.toLowerCase(), mode: vm.mode == null ? null : vm.mode.toLowerCase(),
content: vm.content, 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) Snippet.create(params)
@@ -27,12 +27,12 @@ angular.module('codexen')
return Tag.findByName(tagName) return Tag.findByName(tagName)
.success(function (data) { .success(function (data) {
console.log('tags fetched!!', data) console.log('tags fetched!!', data)
vm.tagCandidates = data.tags vm.tagCandidates = data
}) })
} }
vm.transform = function (tagName) { vm.transform = function (tagName) {
return { return {
_id: 0, id: 0,
name: tagName name: tagName
} }
} }

View File

@@ -1,6 +1,6 @@
/* global angular */ /* global angular */
angular.module('codexen') angular.module('codexen')
.controller('SnippetsDetailController', function (Snippet, $state, $rootScope) { .controller('SnippetsDetailController', function (Snippet, $state, $rootScope, $scope) {
var vm = this var vm = this
vm.isLoaded = false vm.isLoaded = false
@@ -23,4 +23,9 @@ angular.module('codexen')
$rootScope.$broadcast('snippetDeleted') $rootScope.$broadcast('snippetDeleted')
}) })
} }
$scope.$on('snippetUpdated', function (e, snippet) {
console.log('event received', snippet)
if (snippet.id === vm.snippet.id) vm.snippet = snippet
})
}) })

View File

@@ -34,7 +34,7 @@ angular.module('codexen')
}) })
$scope.$on('snippetUpdated', function (e, snippet) { $scope.$on('snippetUpdated', function (e, snippet) {
$state.go('snippets.detail', {id: snippet._id}) $state.go('snippets.detail', {id: snippet.id})
loadSnippets() loadSnippets()
}) })

View File

@@ -6,7 +6,6 @@ angular.module('codexen')
el.on('click', function () { el.on('click', function () {
Modal.newSnippet() Modal.newSnippet()
.result.then(function (snippet) { .result.then(function (snippet) {
console.log('event fire', snippet)
$rootScope.$broadcast('snippetUpdated', snippet) $rootScope.$broadcast('snippetUpdated', snippet)
}, function () { }, function () {
console.log('new snippet modal dismissed') console.log('new snippet modal dismissed')

View File

@@ -32,7 +32,4 @@
<li ui-sref-active="active"> <li ui-sref-active="active">
<a ui-sref="snippets"><i class="fa fa-code"></i> Snippets</a> <a ui-sref="snippets"><i class="fa fa-code"></i> Snippets</a>
</li> </li>
<li ui-sref-active="active">
<a><i class="fa fa-paperclip"></i> Clips(ready)</a>
</li>
</ul> </ul>

View File

@@ -31,10 +31,10 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<ui-select multiple tagging="vm.transform" tagging-tokens="SPACE|,|/" ng-model="vm.tags" theme="bootstrap"> <ui-select multiple tagging="vm.transform" tagging-tokens="SPACE|,|/" ng-model="vm.Tags" theme="bootstrap">
<ui-select-match placeholder="Tags...">{{$item.name}}</ui-select-match> <ui-select-match placeholder="Tags...">{{$item.name}}</ui-select-match>
<ui-select-choices repeat="tag in vm.tagCandidates" refresh="vm.refreshTagCandidates($select.search)" <ui-select-choices repeat="tag in vm.tagCandidates" refresh="vm.refreshTagCandidates($select.search)"
refresh-delay="200"> refresh-delay="100">
<div><span ng-bind-html="tag.name | highlight: $select.search"></span><span ng-if="tag.isTag">(new)</span></div> <div><span ng-bind-html="tag.name | highlight: $select.search"></span><span ng-if="tag.isTag">(new)</span></div>
</ui-select-choices> </ui-select-choices>
</ui-select> </ui-select>