Update image list to fetch images from GitHub
This commit is contained in:
@@ -79,10 +79,11 @@ module.exports = class ItemPageController extends PageController
|
||||
@_usedToMakeController = @addChild ItemGroupController, '.view__item_group.usedToMake', options
|
||||
|
||||
@_descriptionController = @addChild MarkdownSectionController, '.section.description',
|
||||
editable: true
|
||||
modPack: @modPack
|
||||
client: @client
|
||||
editable: true
|
||||
modPack: @modPack
|
||||
beginEditing: => @_beginEditingDescription()
|
||||
endEditing: => @_endEditingDescription()
|
||||
endEditing: => @_endEditingDescription()
|
||||
|
||||
@$byline = @$('.byline')
|
||||
@$bylineLink = @$('.byline a')
|
||||
@@ -157,19 +158,22 @@ module.exports = class ItemPageController extends PageController
|
||||
@client.fetchFile path:GitHub.file.itemDescription modSlug:@_itemSlug.mod, itemSlug:@_itemSlug.item
|
||||
.then (response)=>
|
||||
@_editingFile = response.json.data
|
||||
@_editingFile.content = new Buffer(@_editingFile.content, 'base64').toString('utf8')
|
||||
|
||||
if @_editingFile.content.length > 0
|
||||
@model.item.parse @_editingFile.content
|
||||
else
|
||||
@model.item.description = ''
|
||||
|
||||
@_descriptionController.model = @model.item.description
|
||||
@_descriptionController.loadImages()
|
||||
|
||||
_endEditingDescription: ->
|
||||
oldDescription = @model.item.description
|
||||
@model.item.description = @_descriptionController.model
|
||||
|
||||
args =
|
||||
content: @model.item.unparse()
|
||||
content: new Buffer(@model.item.unparse(), 'utf8').toString('base64')
|
||||
message: "User-submitted text for #{@model.item.name}"
|
||||
path: GitHub.file.itemDescription modSlug:@_itemSlug.mod, itemSlug:@_itemSlug.item
|
||||
sha: @_editingFile.sha
|
||||
|
||||
@@ -5,6 +5,7 @@ Copyright (c) 2015 by Redwood Labs
|
||||
All rights reserved.
|
||||
###
|
||||
|
||||
_ = require 'underscore'
|
||||
BaseController = require './base_controller'
|
||||
|
||||
########################################################################################################################
|
||||
@@ -25,6 +26,8 @@ module.exports = class MarkdownImageController extends BaseController
|
||||
super
|
||||
|
||||
refresh: ->
|
||||
logger.debug "refreshing with model: #{@model.mimeType}, #{_.ellipsize(@model.encodedData)}"
|
||||
|
||||
if @model.mimeType? and @model.encodedData?
|
||||
@$image.attr 'src', "data:#{@model.mimeType};base64,#{@model.encodedData}"
|
||||
else
|
||||
|
||||
@@ -6,6 +6,7 @@ All rights reserved.
|
||||
###
|
||||
|
||||
BaseController = require './base_controller'
|
||||
{Event} = require '../constants'
|
||||
MarkdownImageController = require './markdown_image_controller'
|
||||
MarkdownImageList = require '../models/markdown_image_list'
|
||||
|
||||
@@ -14,12 +15,30 @@ MarkdownImageList = require '../models/markdown_image_list'
|
||||
module.exports = class MarkdownImageListController extends BaseController
|
||||
|
||||
constructor: (options={})->
|
||||
options.model ?= new MarkdownImageList
|
||||
options.model ?= new MarkdownImageList {}, {client:options.client}
|
||||
options.templateName = 'markdown_image_list'
|
||||
super options
|
||||
|
||||
@imageBase = ''
|
||||
|
||||
# Public Methods ###############################################################################
|
||||
|
||||
loadImages: ->
|
||||
@model.loadImages()
|
||||
|
||||
# Property Methods #############################################################################
|
||||
|
||||
getImageBase: ->
|
||||
return @_imageBase
|
||||
|
||||
setImageBase: (newImageBase)->
|
||||
oldImageBase = @_imageBase
|
||||
return unless oldImageBase isnt newImageBase
|
||||
|
||||
@_imageBase = newImageBase
|
||||
@trigger Event.change + ':imageBase', this, oldImageBase, newImageBase
|
||||
@trigger Event.change, this
|
||||
|
||||
getMarkdownText: ->
|
||||
return @model.markdownText
|
||||
|
||||
@@ -27,6 +46,7 @@ module.exports = class MarkdownImageListController extends BaseController
|
||||
@model.markdownText = markdownText
|
||||
|
||||
Object.defineProperties @prototype,
|
||||
imageBase: {get:@prototype.getImageBase, set:@prototype.setImageBase}
|
||||
markdownText: {get:@prototype.getMarkdownText, set:@prototype.setMarkdownText}
|
||||
|
||||
# BaseController Overrides #####################################################################
|
||||
|
||||
@@ -36,6 +36,7 @@ module.exports = class MarkdownSectionController extends BaseController
|
||||
@on Event.animate.hide.finish, => @_updateStateVisibility()
|
||||
@on Event.animate.show.finish, => @_updateStateVisibility()
|
||||
|
||||
@client = options.client
|
||||
@confirmactionMessage = options.confirmationMessage
|
||||
@confirmDuration = options.confirmationDuration ?= 5000
|
||||
@imageBase = options.imageBase ?= ''
|
||||
@@ -53,6 +54,9 @@ module.exports = class MarkdownSectionController extends BaseController
|
||||
|
||||
# Public Methods ###############################################################################
|
||||
|
||||
loadImages: ->
|
||||
@_imageListController.loadImages()
|
||||
|
||||
resetToDefaultState: ->
|
||||
if @model?
|
||||
@state = State.viewing
|
||||
@@ -114,6 +118,17 @@ module.exports = class MarkdownSectionController extends BaseController
|
||||
isEditable: ->
|
||||
return _.isFunction(@_beginEditing) and _.isFunction(@_endEditing)
|
||||
|
||||
getImageBase: ->
|
||||
return @_imageBase
|
||||
|
||||
setImageBase: (newImageBase)->
|
||||
oldImageBase = @_imageBase
|
||||
return unless newImageBase isnt oldImageBase
|
||||
|
||||
@_imageBase = newImageBase
|
||||
@trigger Event.change + ':imageBase', this, oldImageBase, newImageBase
|
||||
@trigger Event.change, this
|
||||
|
||||
getState: ->
|
||||
return @_state
|
||||
|
||||
@@ -127,13 +142,17 @@ module.exports = class MarkdownSectionController extends BaseController
|
||||
@_updateStateVisibility()
|
||||
|
||||
Object.defineProperties @prototype,
|
||||
editable: {get:@prototype.isEditable}
|
||||
state: {get:@prototype.getState, set:@prototype.setState}
|
||||
editable: {get:@prototype.isEditable}
|
||||
imageBase: {get:@prototype.getImageBase, set:@prototype.setImageBase}
|
||||
state: {get:@prototype.getState, set:@prototype.setState}
|
||||
|
||||
# BaseController Overrides #####################################################################
|
||||
|
||||
onDidRender: ->
|
||||
@_imageListController = @addChild MarkdownImageListController, '.image_list'
|
||||
@_imageListController = @addChild MarkdownImageListController, '.image_list',
|
||||
client: @client
|
||||
imageBase: @imageBase
|
||||
@on Event.change + ':imageBase', => @_imageListController.model.imageBase = @imageBase
|
||||
|
||||
@$errorText = @$('.error p')
|
||||
@$markdownPanel = @$('.markdown')
|
||||
|
||||
Reference in New Issue
Block a user