Add error message and disabling of preview button
This commit is contained in:
@@ -166,7 +166,6 @@ module.exports = class ItemPageController extends PageController
|
|||||||
@model.item.description = ''
|
@model.item.description = ''
|
||||||
|
|
||||||
@_descriptionController.model = @model.item.description
|
@_descriptionController.model = @model.item.description
|
||||||
@_descriptionController.loadImages()
|
|
||||||
|
|
||||||
_endEditingDescription: ->
|
_endEditingDescription: ->
|
||||||
oldDescription = @model.item.description
|
oldDescription = @model.item.description
|
||||||
|
|||||||
@@ -89,6 +89,12 @@ module.exports = class MarkdownImageController extends BaseController
|
|||||||
@$loading.hide duration:Duration.normal
|
@$loading.hide duration:Duration.normal
|
||||||
@$loaded.show duration:Duration.normal, queue:true
|
@$loaded.show duration:Duration.normal, queue:true
|
||||||
|
|
||||||
|
if @model.status is MarkdownImage.Status.empty
|
||||||
|
@$errorMessage.html 'please choose an image'
|
||||||
|
@$errorContainer.show duration:Duration.normal
|
||||||
|
else
|
||||||
|
@$errorContainer.hide duration:Duration.normal
|
||||||
|
|
||||||
super
|
super
|
||||||
|
|
||||||
# Backbone.View Overrides ######################################################################
|
# Backbone.View Overrides ######################################################################
|
||||||
|
|||||||
@@ -20,15 +20,13 @@ module.exports = class MarkdownImageListController extends BaseController
|
|||||||
super options
|
super options
|
||||||
|
|
||||||
@imageBase = ''
|
@imageBase = ''
|
||||||
|
@_valid = null
|
||||||
|
|
||||||
# Public Methods ###############################################################################
|
# Public Methods ###############################################################################
|
||||||
|
|
||||||
getImageUrlForFile: (fileName)->
|
getImageUrlForFile: (fileName)->
|
||||||
@model.getImageUrlForFile fileName
|
@model.getImageUrlForFile fileName
|
||||||
|
|
||||||
loadImages: ->
|
|
||||||
@model.loadImages()
|
|
||||||
|
|
||||||
reset: ->
|
reset: ->
|
||||||
@model.reset()
|
@model.reset()
|
||||||
|
|
||||||
@@ -51,17 +49,27 @@ module.exports = class MarkdownImageListController extends BaseController
|
|||||||
setMarkdownText: (markdownText)->
|
setMarkdownText: (markdownText)->
|
||||||
@model.markdownText = markdownText
|
@model.markdownText = markdownText
|
||||||
|
|
||||||
|
getValid: ->
|
||||||
|
return @_valid
|
||||||
|
|
||||||
Object.defineProperties @prototype,
|
Object.defineProperties @prototype,
|
||||||
imageBase: {get:@prototype.getImageBase, set:@prototype.setImageBase}
|
imageBase: {get:@prototype.getImageBase, set:@prototype.setImageBase}
|
||||||
markdownText: {get:@prototype.getMarkdownText, set:@prototype.setMarkdownText}
|
markdownText: {get:@prototype.getMarkdownText, set:@prototype.setMarkdownText}
|
||||||
|
valid: {get:@prototype.getValid}
|
||||||
|
|
||||||
# BaseController Overrides #####################################################################
|
# BaseController Overrides #####################################################################
|
||||||
|
|
||||||
|
onDidModelChange: ->
|
||||||
|
super
|
||||||
|
@_setValid @model.valid
|
||||||
|
|
||||||
onDidRender: ->
|
onDidRender: ->
|
||||||
@$imageContainer = @$('.image_container')
|
@$imageContainer = @$('.image_container')
|
||||||
super
|
super
|
||||||
|
|
||||||
refresh: ->
|
refresh: ->
|
||||||
|
@model.loadImages()
|
||||||
|
|
||||||
@_controllers ?= []
|
@_controllers ?= []
|
||||||
index = 0
|
index = 0
|
||||||
|
|
||||||
@@ -79,3 +87,14 @@ module.exports = class MarkdownImageListController extends BaseController
|
|||||||
|
|
||||||
while @_controllers.length > index
|
while @_controllers.length > index
|
||||||
@_controllers.pop().remove()
|
@_controllers.pop().remove()
|
||||||
|
|
||||||
|
# Private Methods ##############################################################################
|
||||||
|
|
||||||
|
_setValid: (newValid)->
|
||||||
|
oldValid = @_valid
|
||||||
|
return if newValid is oldValid
|
||||||
|
|
||||||
|
@_valid = newValid
|
||||||
|
logger.debug "setting mic.valid to #{@_valid}"
|
||||||
|
@trigger Event.change + ':valid', this, oldValid, newValid
|
||||||
|
@trigger Event.change
|
||||||
|
|||||||
@@ -54,9 +54,6 @@ module.exports = class MarkdownSectionController extends BaseController
|
|||||||
|
|
||||||
# Public Methods ###############################################################################
|
# Public Methods ###############################################################################
|
||||||
|
|
||||||
loadImages: ->
|
|
||||||
@_imageListController.loadImages()
|
|
||||||
|
|
||||||
resetToDefaultState: ->
|
resetToDefaultState: ->
|
||||||
if @model?
|
if @model?
|
||||||
@state = State.viewing
|
@state = State.viewing
|
||||||
@@ -157,9 +154,12 @@ module.exports = class MarkdownSectionController extends BaseController
|
|||||||
client: @client
|
client: @client
|
||||||
imageBase: @imageBase
|
imageBase: @imageBase
|
||||||
@on Event.change + ':imageBase', => @_imageListController.model.imageBase = @imageBase
|
@on Event.change + ':imageBase', => @_imageListController.model.imageBase = @imageBase
|
||||||
|
@listenTo @_imageListController, Event.change + ':valid', => @tryRefresh()
|
||||||
|
|
||||||
@$errorText = @$('.error p')
|
@$errorText = @$('.error p')
|
||||||
@$markdownPanel = @$('.markdown')
|
@$markdownPanel = @$('.markdown')
|
||||||
|
@$previewButton = @$('button.preview')
|
||||||
|
@$saveButton = @$('button.save')
|
||||||
@$sizer = @$('.sizer')
|
@$sizer = @$('.sizer')
|
||||||
@$textarea = @$('textarea')
|
@$textarea = @$('textarea')
|
||||||
@$title = @$('h2')
|
@$title = @$('h2')
|
||||||
@@ -172,6 +172,7 @@ module.exports = class MarkdownSectionController extends BaseController
|
|||||||
@$title.html @title
|
@$title.html @title
|
||||||
@_imageListController.markdownText = @model
|
@_imageListController.markdownText = @model
|
||||||
|
|
||||||
|
@_updateButtonStates()
|
||||||
@_updateSizer()
|
@_updateSizer()
|
||||||
@_updatePreview()
|
@_updatePreview()
|
||||||
super
|
super
|
||||||
@@ -208,6 +209,14 @@ module.exports = class MarkdownSectionController extends BaseController
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
_updateButtonStates: ->
|
||||||
|
for $button in [ @$previewButton, @$saveButton ]
|
||||||
|
logger.debug "updating buttons based upon valid state: #{@_imageListController.valid}"
|
||||||
|
if @_imageListController.valid
|
||||||
|
$button.prop 'disabled', false
|
||||||
|
else
|
||||||
|
$button.prop 'disabled', true
|
||||||
|
|
||||||
_updateSizer: ->
|
_updateSizer: ->
|
||||||
text = @model
|
text = @model
|
||||||
if @model?
|
if @model?
|
||||||
@@ -239,9 +248,9 @@ module.exports = class MarkdownSectionController extends BaseController
|
|||||||
errorPanel: @$('.error')
|
errorPanel: @$('.error')
|
||||||
imageList: @$('.image_list')
|
imageList: @$('.image_list')
|
||||||
markdownPanel: @$markdownPanel
|
markdownPanel: @$markdownPanel
|
||||||
previewButton: @$('button.preview')
|
previewButton: @$previewButton
|
||||||
returnButton: @$('button.return')
|
returnButton: @$('button.return')
|
||||||
saveButton: @$('button.save')
|
saveButton: @$saveButton
|
||||||
waitingPanel: @$('.waiting')
|
waitingPanel: @$('.waiting')
|
||||||
|
|
||||||
visible = {}
|
visible = {}
|
||||||
|
|||||||
@@ -61,10 +61,14 @@ module.exports = class MarkdownImage extends BaseModel
|
|||||||
|
|
||||||
return @_mimeType
|
return @_mimeType
|
||||||
|
|
||||||
|
isValid: ->
|
||||||
|
return @status in [ Status.creatable, Status.unchanged, Status.updateable ]
|
||||||
|
|
||||||
Object.defineProperties @prototype,
|
Object.defineProperties @prototype,
|
||||||
fullPath: {get:@prototype.getFullPath}
|
fullPath: {get:@prototype.getFullPath}
|
||||||
imageUrl: {get:@prototype.getImageUrl}
|
imageUrl: {get:@prototype.getImageUrl}
|
||||||
mimeType: {get:@prototype.getMimeType}
|
mimeType: {get:@prototype.getMimeType}
|
||||||
|
valid: {get:@prototype.isValid}
|
||||||
|
|
||||||
# BaseModel Overrides ##########################################################################
|
# BaseModel Overrides ##########################################################################
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,9 @@ module.exports = class MarkdownImageList extends BaseModel
|
|||||||
image.fetch()
|
image.fetch()
|
||||||
|
|
||||||
reset: ->
|
reset: ->
|
||||||
|
for fileName, image of @_images
|
||||||
|
@stopListening image
|
||||||
|
|
||||||
@_images = {}
|
@_images = {}
|
||||||
@_analyzeMarkdownText()
|
@_analyzeMarkdownText()
|
||||||
|
|
||||||
@@ -54,13 +57,19 @@ module.exports = class MarkdownImageList extends BaseModel
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
isValid: ->
|
||||||
|
for fileName, image of @_images
|
||||||
|
return false unless image.valid
|
||||||
|
return true
|
||||||
|
|
||||||
Object.defineProperties @prototype,
|
Object.defineProperties @prototype,
|
||||||
all: {get:@prototype.getAll}
|
all: {get:@prototype.getAll}
|
||||||
|
valid: {get:@prototype.isValid}
|
||||||
|
|
||||||
# Private Methods ##############################################################################
|
# Private Methods ##############################################################################
|
||||||
|
|
||||||
_analyzeMarkdownText: ->
|
_analyzeMarkdownText: ->
|
||||||
regex = /\!\[([^\]]*)\]\(([^\)]*)\)/g
|
regex = /\!\[([^\]\n]*)\]\(([^\)\n]*)\)/g
|
||||||
newImages = {}
|
newImages = {}
|
||||||
changed = false
|
changed = false
|
||||||
|
|
||||||
@@ -73,6 +82,7 @@ module.exports = class MarkdownImageList extends BaseModel
|
|||||||
image = @_images[fileName]
|
image = @_images[fileName]
|
||||||
if not image?
|
if not image?
|
||||||
image = new MarkdownImage {fileName:fileName, path:@imageBase}, {client:@client}
|
image = new MarkdownImage {fileName:fileName, path:@imageBase}, {client:@client}
|
||||||
|
@listenTo image, Event.change, => @trigger Event.change, this
|
||||||
@trigger Event.add, this, image
|
@trigger Event.add, this, image
|
||||||
changed = true
|
changed = true
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,9 @@
|
|||||||
.view__markdown_image
|
.view__markdown_image
|
||||||
.loaded
|
.loaded
|
||||||
.thumbnail: img
|
.thumbnail: img
|
||||||
.fileName: p
|
.dynamic
|
||||||
|
.fileName: p
|
||||||
|
.error: p
|
||||||
button
|
button
|
||||||
input(type="file", accept="image/gif,image/jpeg,image/png" multiple="false")
|
input(type="file", accept="image/gif,image/jpeg,image/png" multiple="false")
|
||||||
.error: p
|
|
||||||
.loading: p checking for image...
|
.loading: p checking for image...
|
||||||
|
|||||||
@@ -31,6 +31,12 @@ button {
|
|||||||
color: $color-active-hover;
|
color: $color-active-hover;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&:disabled {
|
||||||
|
background: $color-white !important;
|
||||||
|
color: $color-gray-light !important;
|
||||||
|
cursor: default !important;
|
||||||
|
}
|
||||||
|
|
||||||
&.large {
|
&.large {
|
||||||
margin: 2em 0;
|
margin: 2em 0;
|
||||||
padding: 0.5em 0.5em;
|
padding: 0.5em 0.5em;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ All rights reserved.
|
|||||||
position: relative; min-width: 33em;
|
position: relative; min-width: 33em;
|
||||||
|
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
margin: 1em 2em 0 0;
|
margin: 0 2em 1em 0;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
vertical-align: top;
|
vertical-align: top;
|
||||||
|
|
||||||
@@ -27,13 +27,16 @@ All rights reserved.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.fileName {
|
.dynamic {
|
||||||
height: 3em;
|
min-height: 7.5em; min-width: 22em;
|
||||||
|
margin: 0 0 3.5em 11em;
|
||||||
|
|
||||||
margin: 1em 0 7em 11em;
|
.fileName {
|
||||||
|
min-height: 2em;
|
||||||
|
|
||||||
p {
|
p {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user