package.coffee 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. class Index extends App.ControllerContent
  2. events:
  3. 'click .action': 'action'
  4. constructor: ->
  5. super
  6. # check authentication
  7. return if !@authenticate()
  8. @title 'Packages', true
  9. @load()
  10. load: ->
  11. @ajax(
  12. id: 'packages',
  13. type: 'GET',
  14. url: "#{@apiPath}/packages",
  15. processData: true,
  16. success: (data) =>
  17. @packages = data
  18. @render()
  19. )
  20. render: ->
  21. for item in @packages
  22. item.action = []
  23. if item.state == 'installed'
  24. # item.action = ['uninstall', 'deactivate']
  25. item.action = ['uninstall']
  26. else if item.state == 'uninstalled'
  27. item.action = ['install']
  28. else if item.state == 'deactivate'
  29. item.action = ['uninstall', 'activate']
  30. @html App.view('package')(
  31. head: 'Dashboard'
  32. packages: @packages
  33. )
  34. action: (e) ->
  35. e.preventDefault()
  36. id = $(e.target).parents('[data-id]').data('id')
  37. type = $(e.target).data('type')
  38. if type is 'uninstall'
  39. httpType = 'DELETE'
  40. if httpType
  41. @ajax(
  42. id: 'packages'
  43. type: httpType
  44. url: "#{@apiPath}/packages",
  45. data: JSON.stringify( { id: id } )
  46. processData: false
  47. success: =>
  48. @load()
  49. )
  50. App.Config.set( 'Packages', { prio: 1000, name: 'Packages', parent: '#system', target: '#system/package', controller: Index, role: ['Admin'] }, 'NavBarAdmin' )