Added related achievements tab to level editor
This commit is contained in:
parent
7d7d5300c0
commit
d42922871e
8 changed files with 52 additions and 23 deletions
app
styles
templates/editor
views
server/achievements
|
@ -218,3 +218,6 @@ h2.achievements-category
|
||||||
.table-layout
|
.table-layout
|
||||||
#no-achievements
|
#no-achievements
|
||||||
margin-top: 40px
|
margin-top: 40px
|
||||||
|
|
||||||
|
.achievement-icon-small
|
||||||
|
height: 18px
|
||||||
|
|
6
app/styles/editor/related-achievements.sass
Normal file
6
app/styles/editor/related-achievements.sass
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#related-achievements-view
|
||||||
|
#new-achievement-button
|
||||||
|
margin-bottom: 10px
|
||||||
|
|
||||||
|
.icon-column
|
||||||
|
width: 25px
|
26
app/templates/editor/related-achievements.jade
Normal file
26
app/templates/editor/related-achievements.jade
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
|
||||||
|
button.btn.btn-primary#new-achievement-button(disabled=me.isAdmin() === true ? undefined : "true" data-i18n="editor.new_achievement_title") Create a New Achievement
|
||||||
|
|
||||||
|
if achievements.loading
|
||||||
|
h2 Loading...
|
||||||
|
else if ! achievements.models.length
|
||||||
|
.panel
|
||||||
|
.panel-body
|
||||||
|
p No achievements added for this level yet.
|
||||||
|
else
|
||||||
|
table.table.table-hover
|
||||||
|
thead
|
||||||
|
tr
|
||||||
|
th
|
||||||
|
th Name
|
||||||
|
th Description
|
||||||
|
th XP
|
||||||
|
tbody
|
||||||
|
each achievement in achievements.models
|
||||||
|
tr
|
||||||
|
td(style="width: 20px")
|
||||||
|
img.achievement-icon-small(src=achievement.getImageURL() alt="#{achievement.get('name') icon")
|
||||||
|
td
|
||||||
|
a(href="/editor/achievement/#{achievement.get('slug')}")= achievement.get('name')
|
||||||
|
td= achievement.get('description')
|
||||||
|
td= achievement.get('worth')
|
|
@ -1,18 +0,0 @@
|
||||||
|
|
||||||
if achievements.loading
|
|
||||||
h2 Loading...
|
|
||||||
else if ! achievements.models.length
|
|
||||||
.panel
|
|
||||||
.panel-body
|
|
||||||
p No achievements added for this level yet.
|
|
||||||
else
|
|
||||||
table
|
|
||||||
tr
|
|
||||||
th Name
|
|
||||||
th Description
|
|
||||||
th XP
|
|
||||||
each achievement in achievements.models
|
|
||||||
tr
|
|
||||||
td= achievement.get('name')
|
|
||||||
td= achievement.get('description')
|
|
||||||
td= achievement.get('worth')
|
|
|
@ -1,13 +1,18 @@
|
||||||
CocoView = require 'views/kinds/CocoView'
|
CocoView = require 'views/kinds/CocoView'
|
||||||
template = require 'templates/editor/related_achievements'
|
template = require 'templates/editor/related-achievements'
|
||||||
RelatedAchievementsCollection = require 'collections/RelatedAchievementsCollection'
|
RelatedAchievementsCollection = require 'collections/RelatedAchievementsCollection'
|
||||||
Achievement = require 'models/Achievement'
|
Achievement = require 'models/Achievement'
|
||||||
|
NewModelModal = require 'views/modal/NewModelModal'
|
||||||
|
app = require 'application'
|
||||||
|
|
||||||
module.exports = class RelatedAchievementsView extends CocoView
|
module.exports = class RelatedAchievementsView extends CocoView
|
||||||
id: 'related-achievements-view'
|
id: 'related-achievements-view'
|
||||||
template: template
|
template: template
|
||||||
className: 'tab-pane'
|
className: 'tab-pane'
|
||||||
|
|
||||||
|
events:
|
||||||
|
'click #new-achievement-button': 'makeNewAchievement'
|
||||||
|
|
||||||
constructor: (options) ->
|
constructor: (options) ->
|
||||||
super options
|
super options
|
||||||
@relatedID = options.relatedID
|
@relatedID = options.relatedID
|
||||||
|
@ -29,3 +34,11 @@ module.exports = class RelatedAchievementsView extends CocoView
|
||||||
render: ->
|
render: ->
|
||||||
console.debug 'rendering achievements'
|
console.debug 'rendering achievements'
|
||||||
super()
|
super()
|
||||||
|
|
||||||
|
onNewAchievementSaved: (achievement) ->
|
||||||
|
app.router.navigate('/editor/achievement/' + (achievement.get('slug') or achievement.id), {trigger: true})
|
||||||
|
|
||||||
|
makeNewAchievement: ->
|
||||||
|
modal = new NewModelModal model: Achievement, modelLabel: 'Achievement', properties: related: @relatedID
|
||||||
|
modal.once 'success', @onNewAchievementSaved
|
||||||
|
@openModalView modal
|
||||||
|
|
|
@ -78,8 +78,6 @@ module.exports = class SearchView extends RootView
|
||||||
@collection = null
|
@collection = null
|
||||||
|
|
||||||
onNewModelSaved: (@model) ->
|
onNewModelSaved: (@model) ->
|
||||||
# Can only redirect after the modal hidden event has triggered
|
|
||||||
console.debug 'new model saved'
|
|
||||||
base = document.location.pathname[1..] + '/'
|
base = document.location.pathname[1..] + '/'
|
||||||
app.router.navigate(base + (@model.get('slug') or @model.id), {trigger: true})
|
app.router.navigate(base + (@model.get('slug') or @model.id), {trigger: true})
|
||||||
|
|
||||||
|
|
|
@ -12,11 +12,11 @@ module.exports = class NewModelModal extends ModalView
|
||||||
'submit form': 'makeNewModel'
|
'submit form': 'makeNewModel'
|
||||||
'shown.bs.modal #new-model-modal': 'focusOnName'
|
'shown.bs.modal #new-model-modal': 'focusOnName'
|
||||||
|
|
||||||
|
|
||||||
constructor: (options) ->
|
constructor: (options) ->
|
||||||
super options
|
super options
|
||||||
@model = options.model
|
@model = options.model
|
||||||
@modelLabel = options.modelLabel
|
@modelLabel = options.modelLabel
|
||||||
|
@properties = options.properties
|
||||||
|
|
||||||
getRenderData: ->
|
getRenderData: ->
|
||||||
c = super()
|
c = super()
|
||||||
|
@ -31,6 +31,7 @@ module.exports = class NewModelModal extends ModalView
|
||||||
model.set('name', name)
|
model.set('name', name)
|
||||||
if @model.schema.properties.permissions
|
if @model.schema.properties.permissions
|
||||||
model.set 'permissions', [{access: 'owner', target: me.id}]
|
model.set 'permissions', [{access: 'owner', target: me.id}]
|
||||||
|
model.set(key, prop) for key, prop of @properties if @properties?
|
||||||
res = model.save()
|
res = model.save()
|
||||||
return unless res
|
return unless res
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ class AchievementHandler extends Handler
|
||||||
modelClass: Achievement
|
modelClass: Achievement
|
||||||
|
|
||||||
# Used to determine which properties requests may edit
|
# Used to determine which properties requests may edit
|
||||||
editableProperties: ['name', 'query', 'worth', 'collection', 'description', 'userField', 'proportionalTo', 'icon', 'function']
|
editableProperties: ['name', 'query', 'worth', 'collection', 'description', 'userField', 'proportionalTo', 'icon', 'function', 'related', 'difficulty', 'category']
|
||||||
jsonSchema = require '../../app/schemas/models/achievement.coffee'
|
jsonSchema = require '../../app/schemas/models/achievement.coffee'
|
||||||
|
|
||||||
hasAccess: (req) ->
|
hasAccess: (req) ->
|
||||||
|
|
Reference in a new issue