codecombat/app/models/Campaign.coffee
Scott Erickson d4c5d418ff Improve CampaignEditor saving, particularly level order
* Do not cache campaign
* Instead have an on leave message if there are unsaved changes
* Propagate campaignIndex values to campaign and levels so that they signal a change in order

 The save modal seems to have a lot of issues with identifying what models have
 changed. I tried using different methods, but none were consistent. Moving on
 to other bugs.
2016-05-31 15:09:26 -07:00

25 lines
889 B
CoffeeScript

CocoModel = require './CocoModel'
schema = require 'schemas/models/campaign.schema'
Level = require 'models/Level'
Levels = require 'collections/Levels'
CocoCollection = require 'collections/CocoCollection'
module.exports = class Campaign extends CocoModel
@className: 'Campaign'
@schema: schema
urlRoot: '/db/campaign'
@denormalizedLevelProperties: _.keys(_.omit(schema.properties.levels.additionalProperties.properties, ['unlocks', 'position', 'rewards']))
@denormalizedCampaignProperties: ['name', 'i18n', 'slug']
getLevels: ->
levels = new Levels(_.values(@get('levels')))
levels.comparator = 'campaignIndex'
levels.sort()
return levels
getNonLadderLevels: ->
levels = new Levels(_.values(@get('levels')))
levels.reset(levels.reject (level) -> level.isLadder())
levels.comparator = 'campaignIndex'
levels.sort()
return levels