app/assets/javascripts/kms/application/controllers/snippets_controller.coffee.erb in kms-1.0.1 vs app/assets/javascripts/kms/application/controllers/snippets_controller.coffee.erb in kms-1.1.0

- old
+ new

@@ -1,6 +1,6 @@ -SnippetsController = ($scope, $state, Restangular, $stateParams, Alertify, ErrorsService) -> +SnippetsController = ($scope, $state, Restangular, $stateParams, Alertify, ErrorsService, hotkeys) -> $scope.editorOptions = lineNumbers: true mode:'htmlmixed' autoCloseTags: true matchBrackets: true @@ -24,27 +24,37 @@ if $stateParams.id $scope.store.get($stateParams.id).then (snippet)-> $scope.snippet = snippet else - $scope.snippet = {} + $scope.snippet = {content: ''} + hotkeys.add + combo: 'ctrl+s' + description: 'Saving a snippet' + allowIn: ['INPUT', 'SELECT', 'TEXTAREA'] + callback: (event) -> + event.preventDefault() + if $scope.snippet.id then $scope.update(event) else $scope.create() + $scope.create = -> $scope.store.post($scope.snippet).then -> $state.go('snippets') + Alertify.success('<%= I18n.t(:snippet_successfully_created) %>') , (response)-> Alertify.error(ErrorsService.prepareErrorsString(response.data.errors)) $scope.update = (event)-> $scope.snippet.put().then -> if event.target.attributes['data-redirect'] $state.go('snippets') + Alertify.success('<%= I18n.t(:snippet_successfully_updated) %>') ,(response)-> Alertify.error(ErrorsService.prepareErrorsString(response.data.errors)) $scope.destroy = (snippet)-> if(confirm('<%= I18n.t(:are_you_sure) %>')) snippet.remove().then -> $scope.snippets = _.without($scope.snippets, snippet) angular.module('KMS') - .controller('SnippetsController', ['$scope', '$state', 'Restangular', '$stateParams', 'Alertify', 'ErrorsService', SnippetsController]) + .controller('SnippetsController', ['$scope', '$state', 'Restangular', '$stateParams', 'Alertify', 'ErrorsService', 'hotkeys', SnippetsController])