Sha256: 42d1f0f1a1f1e7aa3d35de1ed8bbc9bfaed8765f7b1c12d7fe0ae1bd8cb59055

Contents?: true

Size: 1.71 KB

Versions: 2

Compression:

Stored size: 1.71 KB

Contents

TemplatesController = ($scope, $state, $cookieStore, Restangular, $stateParams, Alertify, ErrorsService) ->
  $scope.editorOptions =
    lineNumbers: true
    mode:'htmlmixed'
    autoCloseTags: true
    matchBrackets: true
    autoCloseBrackets: true
    styleActiveLine: 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('templates')
  $scope.store.getList().then (templates)->
    $scope.templates = templates

  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 (template)->
      $scope.template = template
  else
    $scope.template = {}

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

  $scope.update = ($event)->
    $scope.template.put().then ->
      if $event.target.attributes['data-redirect']
        $state.go('templates')
    ,(response)->
      Alertify.error(ErrorsService.prepareErrorsString(response.data.errors))

  $scope.destroy = (template)->
    if(confirm('<%= I18n.t(:are_you_sure) %>'))
      template.remove().then ->
        $scope.templates = _.without($scope.templates, template)


angular.module('KMS')
    .controller('TemplatesController', ['$scope', '$state', '$cookieStore', 'Restangular', '$stateParams', 'Alertify', 'ErrorsService', TemplatesController])

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
kms-1.0.1 app/assets/javascripts/kms/application/controllers/templates_controller.coffee.erb
kms-1.0.0 app/assets/javascripts/kms/application/controllers/templates_controller.coffee.erb