Sha256: e2f19dd8f73360c0c60d06494faa2fdd05b26676f05cf41644dcec6e8cf0f7e8

Contents?: true

Size: 1.58 KB

Versions: 3

Compression:

Stored size: 1.58 KB

Contents

SnippetsController = ($scope, $state, Restangular, $stateParams, Alertify, ErrorsService) ->
  $scope.editorOptions =
    lineNumbers: true
    mode:'htmlmixed'
    autoCloseTags: true
    matchTags:
      bothTags: true
    extraKeys:
      "F11": (cm)->
        cm.setOption("fullScreen", !cm.getOption("fullScreen"))
      "Esc": (cm)->
        if cm.getOption("fullScreen") then cm.setOption("fullScreen", false)

  $scope.store = Restangular.all('snippets')
  $scope.store.getList().then (snippets)->
    $scope.snippets = snippets

  Restangular.all('users').customGET('kms_user').then (current_user) ->
    $scope.currentUser = current_user
    $scope.currentUser.admin = $scope.currentUser.role == 'admin'

  if $stateParams.id
    $scope.store.get($stateParams.id).then (snippet)->
      $scope.snippet = snippet
  else
    $scope.snippet = {}

  $scope.create = ->
    $scope.store.post($scope.snippet).then ->
      $state.go('snippets')
    , (response)->
      Alertify.error(ErrorsService.prepareErrorsString(response.data.errors))

  $scope.update = (event)->
    $scope.snippet.put().then ->
      if event.target.attributes['data-redirect']
        $state.go('snippets')
    ,(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])

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
kms-0.9.0 app/assets/javascripts/kms/application/controllers/snippets_controller.coffee.erb
kms-0.8.0 app/assets/javascripts/kms/application/controllers/snippets_controller.coffee.erb
kms-0.7.0 app/assets/javascripts/kms/application/controllers/snippets_controller.coffee.erb