@@ -5,26 +5,22 @@
|
||||
# All rights reserved.
|
||||
#
|
||||
|
||||
{BaseModel} = require('crafting-guide-common').deprecated
|
||||
{Observable} = require("crafting-guide-common").util
|
||||
MarkdownImage = require './markdown_image'
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
module.exports = class MarkdownImageList extends BaseModel
|
||||
module.exports = class MarkdownImageList extends Observable
|
||||
|
||||
constructor: (attributes={}, options={})->
|
||||
attributes.imageBase ?= ''
|
||||
attributes.markdownText ?= null
|
||||
super attributes, options
|
||||
constructor: (options={})->
|
||||
super
|
||||
|
||||
@client = options.client
|
||||
@_images = {}
|
||||
@_images = []
|
||||
@muted =>
|
||||
@client = options.client
|
||||
@imageBase = options.imageBase
|
||||
@markdownText = options.markdownText
|
||||
|
||||
@on c.event.change + ':imageBase', =>
|
||||
for fileName, image of @_images
|
||||
image.path = @imageBase
|
||||
|
||||
@on c.event.change + ':markdownText', => @_analyzeMarkdownText()
|
||||
@_analyzeMarkdownText()
|
||||
|
||||
# Public Methods ###############################################################################
|
||||
@@ -46,22 +42,43 @@ module.exports = class MarkdownImageList extends BaseModel
|
||||
|
||||
# Property Methods #############################################################################
|
||||
|
||||
getAll: ->
|
||||
fileNames = (fileName for fileName, image of @_images).sort()
|
||||
result = []
|
||||
for fileName in fileNames
|
||||
result.push @_images[fileName]
|
||||
|
||||
return result
|
||||
|
||||
isValid: ->
|
||||
for fileName, image of @_images
|
||||
return false unless image.valid
|
||||
return true
|
||||
|
||||
Object.defineProperties @prototype,
|
||||
all: {get:@prototype.getAll}
|
||||
valid: {get:@prototype.isValid}
|
||||
|
||||
all:
|
||||
get: ->
|
||||
fileNames = (fileName for fileName, image of @_images).sort()
|
||||
result = []
|
||||
for fileName in fileNames
|
||||
result.push @_images[fileName]
|
||||
|
||||
return result
|
||||
|
||||
client:
|
||||
get: -> return @_client
|
||||
set: (client)->
|
||||
if not client? then throw new Error "client is required"
|
||||
@_client = client
|
||||
|
||||
imageBase: ->
|
||||
get: -> return @_imageBase
|
||||
set: (imageBase)->
|
||||
@triggerPropertyChange "imageBase", @_imageBase, imageBase, ->
|
||||
@_imageBase = imageBase
|
||||
for fileName, image of @_images
|
||||
image.path = @imageBase
|
||||
|
||||
markdownText:
|
||||
get: -> return @_markdownText
|
||||
set: (markdownText)->
|
||||
@triggerPropertyChange "markdownText", @_markdownText, markdownText, ->
|
||||
@_markdownText = markdownText
|
||||
@_analyzeMarkdownText()
|
||||
|
||||
valid:
|
||||
get: ->
|
||||
for fileName, image of @_images
|
||||
return false unless image.valid
|
||||
return true
|
||||
|
||||
# Private Methods ##############################################################################
|
||||
|
||||
@@ -79,8 +96,8 @@ module.exports = class MarkdownImageList extends BaseModel
|
||||
image = @_images[fileName]
|
||||
if not image?
|
||||
image = new MarkdownImage {fileName:fileName, path:@imageBase}, {client:@client}
|
||||
@listenTo image, c.event.change, => @trigger c.event.change, this
|
||||
@trigger c.event.add, this, image
|
||||
image.on Observable::CHANGE, this, "_onImageChanged"
|
||||
@trigger Observable::ADD, image
|
||||
changed = true
|
||||
|
||||
newImages[fileName] = image
|
||||
@@ -92,4 +109,7 @@ module.exports = class MarkdownImageList extends BaseModel
|
||||
|
||||
if changed
|
||||
@_images = newImages
|
||||
@trigger c.event.change, this
|
||||
@trigger Observable::CHANGE
|
||||
|
||||
_onImageChanged: ->
|
||||
@trigger Observable::CHANGE
|
||||
|
||||
@@ -16,7 +16,7 @@ list = null
|
||||
describe 'markdown_image_list.coffee', ->
|
||||
|
||||
beforeEach ->
|
||||
list = new MarkdownImageList {}, client:{fetchFile:sinon.stub().returns(w.promise(->))}
|
||||
list = new MarkdownImageList client:{fetchFile:sinon.stub().returns(w.promise(->))}
|
||||
|
||||
describe '_analyzeMarkdownText', ->
|
||||
|
||||
|
||||
+30
-37
@@ -5,20 +5,24 @@
|
||||
# All rights reserved.
|
||||
#
|
||||
|
||||
BaseController = require '../../../base_controller'
|
||||
MarkdownImageController = require './markdown_image/markdown_image_controller'
|
||||
MarkdownImageList = require '../../../../models/site/markdown_image_list'
|
||||
_ = require "../../../../../underscore"
|
||||
c = require "../../../../../common/constants"
|
||||
BaseController = require "../../../base_controller"
|
||||
MarkdownImageController = require "./markdown_image/markdown_image_controller"
|
||||
MarkdownImageList = require "../../../../models/site/markdown_image_list"
|
||||
{Observable} = require("crafting-guide-common").util
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
module.exports = class MarkdownImageListController extends BaseController
|
||||
_.extend this, Observable
|
||||
|
||||
constructor: (options={})->
|
||||
options.model ?= new MarkdownImageList {}, {client:options.client}
|
||||
options.templateName = 'common/markdown_section/markdown_image_list'
|
||||
options.model ?= new MarkdownImageList client:options.client
|
||||
options.templateName = "common/markdown_section/markdown_image_list"
|
||||
super options
|
||||
|
||||
@imageBase = ''
|
||||
@imageBase = ""
|
||||
@_valid = null
|
||||
|
||||
# Public Methods ###############################################################################
|
||||
@@ -33,31 +37,24 @@ module.exports = class MarkdownImageListController extends BaseController
|
||||
@model.reset()
|
||||
|
||||
# Property Methods #############################################################################
|
||||
|
||||
getImageBase: ->
|
||||
return @_imageBase
|
||||
|
||||
setImageBase: (newImageBase)->
|
||||
oldImageBase = @_imageBase
|
||||
return unless oldImageBase isnt newImageBase
|
||||
|
||||
@_imageBase = newImageBase
|
||||
@trigger c.event.change + ':imageBase', this, oldImageBase, newImageBase
|
||||
@trigger c.event.change, this
|
||||
|
||||
getMarkdownText: ->
|
||||
return @model.markdownText
|
||||
|
||||
setMarkdownText: (markdownText)->
|
||||
@model.markdownText = markdownText
|
||||
|
||||
getValid: ->
|
||||
return @_valid
|
||||
|
||||
|
||||
Object.defineProperties @prototype,
|
||||
imageBase: {get:@prototype.getImageBase, set:@prototype.setImageBase}
|
||||
markdownText: {get:@prototype.getMarkdownText, set:@prototype.setMarkdownText}
|
||||
valid: {get:@prototype.getValid}
|
||||
|
||||
imageBase:
|
||||
get: -> return @_imageBase
|
||||
set: (imageBase)->
|
||||
@_imageBase = imageBase
|
||||
@trigger c.event.change
|
||||
|
||||
markdownText:
|
||||
get: -> return @model.markdownText
|
||||
set: (markdownText)->
|
||||
@model.markdownText = markdownText
|
||||
@trigger c.event.change
|
||||
|
||||
valid:
|
||||
get: -> return @_valid
|
||||
set: -> throw new Error "valid cannot be assigned"
|
||||
|
||||
# BaseController Overrides #####################################################################
|
||||
|
||||
@@ -66,7 +63,7 @@ module.exports = class MarkdownImageListController extends BaseController
|
||||
@_setValid @model.valid
|
||||
|
||||
onDidRender: ->
|
||||
@$imageContainer = @$('.image_container')
|
||||
@$imageContainer = @$(".image_container")
|
||||
super
|
||||
|
||||
refresh: ->
|
||||
@@ -90,10 +87,6 @@ module.exports = class MarkdownImageListController extends BaseController
|
||||
|
||||
# Private Methods ##############################################################################
|
||||
|
||||
_setValid: (newValid)->
|
||||
oldValid = @_valid
|
||||
return if newValid is oldValid
|
||||
|
||||
@_valid = newValid
|
||||
@trigger c.event.change + ':valid', this, oldValid, newValid
|
||||
_setValid: (valid)->
|
||||
@_valid = valid
|
||||
@trigger c.event.change
|
||||
|
||||
@@ -5,28 +5,28 @@
|
||||
# All rights reserved.
|
||||
#
|
||||
|
||||
BaseController = require '../../base_controller'
|
||||
convertMarkdown = require 'marked'
|
||||
BaseController = require "../../base_controller"
|
||||
convertMarkdown = require "marked"
|
||||
ItemDisplay = require "../../../models/site/item_display"
|
||||
MarkdownImageListController = require './markdown_image_list/markdown_image_list_controller'
|
||||
MarkdownImageListController = require "./markdown_image_list/markdown_image_list_controller"
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
module.exports = class MarkdownSectionController extends BaseController
|
||||
|
||||
@::State =
|
||||
appologizing: 'applogizing'
|
||||
confirming: 'confirming'
|
||||
creating: 'creating'
|
||||
editing: 'editing'
|
||||
previewing: 'previewing'
|
||||
viewing: 'viewing'
|
||||
waiting: 'waiting'
|
||||
appologizing: "applogizing"
|
||||
confirming: "confirming"
|
||||
creating: "creating"
|
||||
editing: "editing"
|
||||
previewing: "previewing"
|
||||
viewing: "viewing"
|
||||
waiting: "waiting"
|
||||
|
||||
constructor: (options={})->
|
||||
if not options.modPack? then throw new Error 'options.modPack is required'
|
||||
if not options.modPack? then throw new Error "options.modPack is required"
|
||||
options.model ?= null
|
||||
options.templateName = 'common/markdown_section'
|
||||
options.templateName = "common/markdown_section"
|
||||
@_state = @State.waiting
|
||||
super options
|
||||
|
||||
@@ -34,9 +34,9 @@ module.exports = class MarkdownSectionController extends BaseController
|
||||
@_confirmationMessage = options.confirmationMessage
|
||||
@_confirmDuration = options.confirmationDuration or 5000
|
||||
@_enterFeedback = options.enterFeedback or -> # do nothing
|
||||
@_imageBase = options.imageBase or ''
|
||||
@_imageBase = options.imageBase or ""
|
||||
@_modPack = options.modPack
|
||||
@_title = options.title or 'Description'
|
||||
@_title = options.title or "Description"
|
||||
|
||||
# @_beginEditing must be a function returning a promise which resolves when all actions necessary prior to an
|
||||
# editing session have been completed (e.g., loading the latest content from a remote server). The promise must
|
||||
@@ -61,7 +61,7 @@ module.exports = class MarkdownSectionController extends BaseController
|
||||
# Event Methods ################################################################################
|
||||
|
||||
onCancelClicked: (event)->
|
||||
tracker.trackEvent c.tracking.category.markdown, 'cancel'
|
||||
tracker.trackEvent c.tracking.category.markdown, "cancel"
|
||||
@model = @_originalModel
|
||||
@resetToDefaultState()
|
||||
|
||||
@@ -72,7 +72,7 @@ module.exports = class MarkdownSectionController extends BaseController
|
||||
onEditClicked: (event)->
|
||||
return false unless @editable
|
||||
|
||||
tracker.trackEvent c.tracking.category.markdown, 'edit'
|
||||
tracker.trackEvent c.tracking.category.markdown, "edit"
|
||||
@_originalModel = @model
|
||||
@state = @State.waiting
|
||||
@_beginEditing()
|
||||
@@ -86,22 +86,22 @@ module.exports = class MarkdownSectionController extends BaseController
|
||||
return false
|
||||
|
||||
onQuestionClicked: (event)->
|
||||
@_enterFeedback ''
|
||||
@_enterFeedback ""
|
||||
return false
|
||||
|
||||
onPreviewClicked: (event)->
|
||||
tracker.trackEvent c.tracking.category.markdown, 'preview'
|
||||
tracker.trackEvent c.tracking.category.markdown, "preview"
|
||||
@_updatePreview()
|
||||
@state = @State.previewing
|
||||
return false
|
||||
|
||||
onReturnClicked: (event)->
|
||||
tracker.trackEvent c.tracking.category.markdown, 'return'
|
||||
tracker.trackEvent c.tracking.category.markdown, "return"
|
||||
@state = @State.editing
|
||||
return false
|
||||
|
||||
onSaveClicked: (event)->
|
||||
tracker.trackEvent c.tracking.category.markdown, 'save'
|
||||
tracker.trackEvent c.tracking.category.markdown, "save"
|
||||
@state = @State.waiting
|
||||
@_endEditing()
|
||||
.then =>
|
||||
@@ -133,7 +133,7 @@ module.exports = class MarkdownSectionController extends BaseController
|
||||
return unless newImageBase isnt oldImageBase
|
||||
|
||||
@_imageBase = newImageBase
|
||||
@trigger c.event.change + ':imageBase', this, oldImageBase, newImageBase
|
||||
@trigger c.event.change + ":imageBase", this, oldImageBase, newImageBase
|
||||
@trigger c.event.change, this
|
||||
|
||||
getImageFiles: ->
|
||||
@@ -148,7 +148,7 @@ module.exports = class MarkdownSectionController extends BaseController
|
||||
@_state = newState
|
||||
|
||||
logger.verbose => "MarkdownSectionController.#{@cid} changed state from #{oldState} to #{newState}"
|
||||
@trigger c.event.change + ':state', this, oldState, newState
|
||||
@trigger c.event.change + ":state", this, oldState, newState
|
||||
@tryRefresh()
|
||||
|
||||
Object.defineProperties @prototype,
|
||||
@@ -160,21 +160,21 @@ module.exports = class MarkdownSectionController extends BaseController
|
||||
# BaseController Overrides #####################################################################
|
||||
|
||||
onDidRender: ->
|
||||
@_imageListController = @addChild MarkdownImageListController, '.view__markdown_image_list',
|
||||
@_imageListController = @addChild MarkdownImageListController, ".view__markdown_image_list",
|
||||
client: @_client
|
||||
imageBase: @_imageBase
|
||||
@on c.event.change + ':imageBase', => @_imageListController.model.imageBase = @_imageBase
|
||||
@listenTo @_imageListController, c.event.change + ':valid', => @tryRefresh()
|
||||
@on c.event.change + ":imageBase", => @_imageListController.model.imageBase = @_imageBase
|
||||
@listenTo @_imageListController, c.event.change + ":valid", => @tryRefresh()
|
||||
|
||||
@$errorPanel = @$('.error')
|
||||
@$errorText = @$('.error p')
|
||||
@$markdownPanel = @$('.markdown')
|
||||
@$previewButton = @$('.button.preview')
|
||||
@$questionPanel = @$('.question')
|
||||
@$saveButton = @$('.button.save')
|
||||
@$sizer = @$('.sizer')
|
||||
@$textarea = @$('textarea')
|
||||
@$title = @$('h2')
|
||||
@$errorPanel = @$(".error")
|
||||
@$errorText = @$(".error p")
|
||||
@$markdownPanel = @$(".markdown")
|
||||
@$previewButton = @$(".button.preview")
|
||||
@$questionPanel = @$(".question")
|
||||
@$saveButton = @$(".button.save")
|
||||
@$sizer = @$(".sizer")
|
||||
@$textarea = @$("textarea")
|
||||
@$title = @$("h2")
|
||||
|
||||
@resetToDefaultState()
|
||||
|
||||
@@ -200,14 +200,14 @@ module.exports = class MarkdownSectionController extends BaseController
|
||||
|
||||
events: ->
|
||||
return _.extend super,
|
||||
'click .markdown a': 'routeLinkClick'
|
||||
'click .button.cancel': 'onCancelClicked'
|
||||
'click .button.edit': 'onEditClicked'
|
||||
'click .button.preview': 'onPreviewClicked'
|
||||
'click .button.return': 'onReturnClicked'
|
||||
'click .button.save': 'onSaveClicked'
|
||||
'click .question a': 'onQuestionClicked'
|
||||
'input textarea': 'onTextChanged'
|
||||
"click .markdown a": "routeLinkClick"
|
||||
"click .button.cancel": "onCancelClicked"
|
||||
"click .button.edit": "onEditClicked"
|
||||
"click .button.preview": "onPreviewClicked"
|
||||
"click .button.return": "onReturnClicked"
|
||||
"click .button.save": "onSaveClicked"
|
||||
"click .question a": "onQuestionClicked"
|
||||
"input textarea": "onTextChanged"
|
||||
|
||||
# Private Methods ##############################################################################
|
||||
|
||||
@@ -228,14 +228,14 @@ module.exports = class MarkdownSectionController extends BaseController
|
||||
_updateButtonStates: ->
|
||||
for $button in [ @$previewButton, @$saveButton ]
|
||||
if @_imageListController.valid
|
||||
$button.prop 'disabled', false
|
||||
$button.prop "disabled", false
|
||||
else
|
||||
$button.prop 'disabled', true
|
||||
$button.prop "disabled", true
|
||||
|
||||
_updateSizer: ->
|
||||
text = @model
|
||||
if @model?
|
||||
text = text.replace /\n/g, '<br>'
|
||||
text = text.replace /\n/g, "<br>"
|
||||
|
||||
@$sizer.html text
|
||||
|
||||
@@ -255,22 +255,22 @@ module.exports = class MarkdownSectionController extends BaseController
|
||||
logger.verbose => "Updating markdown section visibility for state: #{@state}"
|
||||
|
||||
elements =
|
||||
appologizingPanel: @$('.appologizing')
|
||||
cancelButton: @$('.button.cancel')
|
||||
confirmingPanel: @$('.confirming')
|
||||
creatingPanel: @$('.creating')
|
||||
editButton: @$('.button.edit')
|
||||
editorPanel: @$('.editor')
|
||||
footerPanel: @$('.footer')
|
||||
imageList: @$('.view__markdown_image_list')
|
||||
appologizingPanel: @$(".appologizing")
|
||||
cancelButton: @$(".button.cancel")
|
||||
confirmingPanel: @$(".confirming")
|
||||
creatingPanel: @$(".creating")
|
||||
editButton: @$(".button.edit")
|
||||
editorPanel: @$(".editor")
|
||||
footerPanel: @$(".footer")
|
||||
imageList: @$(".view__markdown_image_list")
|
||||
markdownPanel: @$markdownPanel
|
||||
previewButton: @$previewButton
|
||||
returnButton: @$('.button.return')
|
||||
returnButton: @$(".button.return")
|
||||
saveButton: @$saveButton
|
||||
waitingPanel: @$('.waiting')
|
||||
waitingPanel: @$(".waiting")
|
||||
|
||||
visible = {}
|
||||
errorText = ''
|
||||
errorText = ""
|
||||
|
||||
if @state is @State.appologizing
|
||||
visible = appologizingPanel:true
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
.content.view__item_page
|
||||
.left
|
||||
include ../common/youtube/youtube.jade
|
||||
// include ../common/youtube/youtube.jade
|
||||
|
||||
.right
|
||||
.about
|
||||
|
||||
@@ -5,17 +5,19 @@
|
||||
# All rights reserved.
|
||||
#
|
||||
|
||||
EditableFile = require "../../models/site/editable_file"
|
||||
{Item} = require("crafting-guide-common").models
|
||||
ItemDisplay = require "../../models/site/item_display"
|
||||
ItemGroupController = require "../common/item_group/item_group_controller"
|
||||
ItemPage = require "../../models/site/item_page"
|
||||
MarkdownSectionController = require "../common/markdown_section/markdown_section_controller"
|
||||
PageController = require "../page_controller"
|
||||
RecipeController = require "../common/recipe/recipe_controller"
|
||||
RecipeDisplay = require "../../models/site/recipe_display"
|
||||
VideoController = require "../common/video/video_controller"
|
||||
w = require "when"
|
||||
EditableFile = require "../../models/site/editable_file"
|
||||
{Item} = require("crafting-guide-common").models
|
||||
{ItemDetail} = require("crafting-guide-common").models
|
||||
{ItemDetailJsonParser} = require("crafting-guide-common").parsing
|
||||
ItemDisplay = require "../../models/site/item_display"
|
||||
ItemGroupController = require "../common/item_group/item_group_controller"
|
||||
ItemPage = require "../../models/site/item_page"
|
||||
MarkdownSectionController = require "../common/markdown_section/markdown_section_controller"
|
||||
PageController = require "../page_controller"
|
||||
RecipeController = require "../common/recipe/recipe_controller"
|
||||
RecipeDisplay = require "../../models/site/recipe_display"
|
||||
VideoController = require "../common/video/video_controller"
|
||||
w = require "when"
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
@@ -52,8 +54,8 @@ module.exports = class ItemPageController extends PageController
|
||||
|
||||
getBreadcrumbs: ->
|
||||
return [
|
||||
$("<a href='/browse'>Browse</a>")
|
||||
$("<a href='#{@model.itemDisplay.modUrl}'>#{@model.itemDisplay.mod.displayName}</a>")
|
||||
$("<a href=\"/browse\">Browse</a>")
|
||||
$("<a href=\"#{@model.itemDisplay.modUrl}\">#{@model.itemDisplay.mod.displayName}</a>")
|
||||
$("<b>#{@model.itemDisplay.name}</b>")
|
||||
]
|
||||
|
||||
@@ -62,7 +64,7 @@ module.exports = class ItemPageController extends PageController
|
||||
return null unless item?
|
||||
|
||||
display = new ItemDisplay item
|
||||
return $("<a href='#{display.url}'>Random Item</a>")
|
||||
return $("<a href=\"#{display.url}\">Random Item</a>")
|
||||
|
||||
getMetaDescription: ->
|
||||
data = itemName:@model.item.displayName, modName:@model.item.mod.displayName
|
||||
@@ -79,11 +81,11 @@ module.exports = class ItemPageController extends PageController
|
||||
|
||||
onDidRender: ->
|
||||
options = imageLoader:@_imageLoader, modPack:@_modPack, router:@_router, show:false
|
||||
@_similarItemsController = @addChild ItemGroupController, '.view__item_group.similar', options
|
||||
@_usedAsToolToMakeController = @addChild ItemGroupController, '.view__item_group.usedAsToolToMake ', options
|
||||
@_usedToMakeController = @addChild ItemGroupController, '.view__item_group.usedToMake', options
|
||||
@_similarItemsController = @addChild ItemGroupController, ".view__item_group.similar", options
|
||||
@_usedAsToolToMakeController = @addChild ItemGroupController, ".view__item_group.usedAsToolToMake ", options
|
||||
@_usedToMakeController = @addChild ItemGroupController, ".view__item_group.usedToMake", options
|
||||
|
||||
@_descriptionController = @addChild MarkdownSectionController, '.view__markdown_section',
|
||||
@_descriptionController = @addChild MarkdownSectionController, ".view__markdown_section",
|
||||
client: @_client
|
||||
editable: true
|
||||
modPack: @_modPack
|
||||
@@ -92,23 +94,23 @@ module.exports = class ItemPageController extends PageController
|
||||
endEditing: => @_endEditingDescription()
|
||||
enterFeedback: @_enterFeedback
|
||||
|
||||
@$aboutImage = @$('.about img')
|
||||
@$craftingPlanButton = @$('.button.craftingPlan')
|
||||
@$name = @$('.about .title')
|
||||
@$officialLink = @$('.about a.officialLink')
|
||||
@$sourceModLink = @$('.about a.sourceMod')
|
||||
@$aboutLinks = @$('.about .right')
|
||||
@$aboutImage = @$(".about img")
|
||||
@$craftingPlanButton = @$(".button.craftingPlan")
|
||||
@$name = @$(".about .title")
|
||||
@$officialLink = @$(".about a.officialLink")
|
||||
@$sourceModLink = @$(".about a.sourceMod")
|
||||
@$aboutLinks = @$(".about .right")
|
||||
|
||||
@$multiblockSection = @$('section.multiblock')
|
||||
@$recipeContainer = @$('section.recipes .panel')
|
||||
@$recipesSection = @$('section.recipes')
|
||||
@$recipesSectionTitle = @$('section.recipes h2')
|
||||
@$similarSection = @$('section.similar')
|
||||
@$usedAsToolToMakeSection = @$('section.usedAsToolToMake')
|
||||
@$usedToMakeSection = @$('section.usedToMake')
|
||||
@$videosContainer = @$('section.videos .panel')
|
||||
@$videosSection = @$('section.videos')
|
||||
@$videosSectionTitle = @$('section.videos h2')
|
||||
@$multiblockSection = @$("section.multiblock")
|
||||
@$recipeContainer = @$("section.recipes .panel")
|
||||
@$recipesSection = @$("section.recipes")
|
||||
@$recipesSectionTitle = @$("section.recipes h2")
|
||||
@$similarSection = @$("section.similar")
|
||||
@$usedAsToolToMakeSection = @$("section.usedAsToolToMake")
|
||||
@$usedToMakeSection = @$("section.usedToMake")
|
||||
@$videosContainer = @$("section.videos .panel")
|
||||
@$videosSection = @$("section.videos")
|
||||
@$videosSectionTitle = @$("section.videos h2")
|
||||
super
|
||||
|
||||
refresh: ->
|
||||
@@ -119,7 +121,7 @@ module.exports = class ItemPageController extends PageController
|
||||
@_descriptionController.imageBase = c.url.itemImageDir @model.itemDisplay
|
||||
|
||||
if @model.item.detail?.links.length > 0
|
||||
@$officialLink.attr 'href', @model.item.detail.links[0]
|
||||
@$officialLink.attr "href", @model.item.detail.links[0]
|
||||
@show @$aboutLinks
|
||||
else
|
||||
@hide @$aboutLinks
|
||||
@@ -155,20 +157,20 @@ module.exports = class ItemPageController extends PageController
|
||||
|
||||
events: ->
|
||||
return _.extend super,
|
||||
'click a.craftingPlan': 'routeLinkClick'
|
||||
'click a.sourceMod': 'routeLinkClick'
|
||||
'click .markdown a': 'routeLinkClick'
|
||||
'click .button.craftingPlan': 'craftingPlanButtonClicked'
|
||||
"click a.craftingPlan": "routeLinkClick"
|
||||
"click a.sourceMod": "routeLinkClick"
|
||||
"click .markdown a": "routeLinkClick"
|
||||
"click .button.craftingPlan": "craftingPlanButtonClicked"
|
||||
|
||||
# Private Methods ##############################################################################
|
||||
|
||||
_beginEditingDescription: ->
|
||||
if not @user?
|
||||
global.site.login()
|
||||
return w.reject new Error 'must be logged in to edit'
|
||||
return w.reject new Error "must be logged in to edit"
|
||||
|
||||
if not @model.item?
|
||||
return w.reject new Error 'must have an item'
|
||||
return w.reject new Error "must have an item"
|
||||
|
||||
pathArgs = modSlug:@model.item.mod.id, itemSlug:@model.itemDisplay.itemSlug
|
||||
attributes =
|
||||
@@ -179,27 +181,29 @@ module.exports = class ItemPageController extends PageController
|
||||
@_descriptionFile.fetch()
|
||||
.then =>
|
||||
if @_descriptionFile.encodedData?.length > 0
|
||||
@model.item.parse @_descriptionFile.getDecodedData 'utf8'
|
||||
parser = new ItemDetailJsonParser item:@model.item
|
||||
parser.parse @_descriptionFile.getDecodedData "utf8"
|
||||
else
|
||||
@model.item.description = ''
|
||||
@model.item.detail = new ItemDetail item:@model.item
|
||||
|
||||
@_descriptionController.model = @model.item.description
|
||||
@_descriptionController.model = @model.item.detail.description
|
||||
|
||||
_endEditingDescription: ->
|
||||
oldDescription = @model.item.description
|
||||
oldDescription = @model.item.detail.description
|
||||
promises = []
|
||||
|
||||
saveList = []
|
||||
for imageFile in @_descriptionController.imageFiles
|
||||
saveList.push
|
||||
file: imageFile
|
||||
message: "User-submitted image for #{@model.item.name} from #{global.hostName}"
|
||||
message: "User-submitted image for #{@model.item.displayName} from #{global.hostName}"
|
||||
|
||||
@model.item.description = @_descriptionController.model
|
||||
@_descriptionFile.setDecodedData @model.item.unparse()
|
||||
@model.item.detail.description = @_descriptionController.model
|
||||
parser = new ItemDetailJsonParser item:@model.item
|
||||
@_descriptionFile.setDecodedData parser.format @model.item.detail
|
||||
saveList.push
|
||||
file: @_descriptionFile
|
||||
message: "User-submitted text for #{@model.item.name} from #{global.hostName}"
|
||||
message: "User-submitted text for #{@model.item.displayName} from #{global.hostName}"
|
||||
|
||||
saveNextFile = (fileList)->
|
||||
return w(true) if fileList.length is 0
|
||||
@@ -211,7 +215,7 @@ module.exports = class ItemPageController extends PageController
|
||||
|
||||
saveNextFile saveList
|
||||
.catch (e)=>
|
||||
@model.item.description = oldDescription
|
||||
@model.item.detail.description = oldDescription
|
||||
throw e
|
||||
|
||||
_refreshDescription: ->
|
||||
@@ -225,7 +229,7 @@ module.exports = class ItemPageController extends PageController
|
||||
|
||||
recipes = @model.findRecipes()
|
||||
if recipes?.length > 0
|
||||
@$recipesSectionTitle.html if recipes.length is 1 then 'Recipe' else 'Recipes'
|
||||
@$recipesSectionTitle.html if recipes.length is 1 then "Recipe" else "Recipes"
|
||||
|
||||
for recipe in recipes
|
||||
controller = @_recipeControllers[index]
|
||||
@@ -263,16 +267,16 @@ module.exports = class ItemPageController extends PageController
|
||||
|
||||
_refreshSourceMod: ->
|
||||
mod = @model.item.mod
|
||||
@$sourceModLink.attr 'href', c.url.mod @model.itemDisplay
|
||||
@$sourceModLink.attr "href", c.url.mod @model.itemDisplay
|
||||
@$sourceModLink.text mod.name
|
||||
@show @$sourceModLink
|
||||
|
||||
_refreshUsedAsToolToMake: ->
|
||||
@_usedAsToolToMakeController.title = 'Used as Tool to Make'
|
||||
@_usedAsToolToMakeController.title = "Used as Tool to Make"
|
||||
@_usedAsToolToMakeController.model = @model.findToolForItems()
|
||||
|
||||
_refreshUsedToMake: ->
|
||||
@_usedToMakeController.title = 'Used to Make'
|
||||
@_usedToMakeController.title = "Used to Make"
|
||||
@_usedToMakeController.model = @model.findComponentInItems()
|
||||
|
||||
_refreshVideos: ->
|
||||
@@ -281,7 +285,7 @@ module.exports = class ItemPageController extends PageController
|
||||
|
||||
videos = @model.item.detail?.videos
|
||||
if videos? and videos.length > 0
|
||||
@$videosSectionTitle.html if videos.length is 1 then 'Video' else 'Videos'
|
||||
@$videosSectionTitle.html if videos.length is 1 then "Video" else "Videos"
|
||||
|
||||
for video in videos
|
||||
controller = @_videoControllers[index]
|
||||
|
||||
@@ -81,7 +81,7 @@ duration.slow = 1200
|
||||
exports.gitHub = gitHub = {}
|
||||
gitHub.file = {}
|
||||
gitHub.file.itemDescription = {}
|
||||
gitHub.file.itemDescription.fileName = _.template "item.cg"
|
||||
gitHub.file.itemDescription.fileName = _.template "item.json"
|
||||
gitHub.file.itemDescription.path = _.template "/data/<%= modSlug %>/items/<%= itemSlug %>"
|
||||
|
||||
exports.key = key = {}
|
||||
|
||||
Reference in New Issue
Block a user