### window.SetContentTo = function(id, content){ $(id).val(content); } window.GetContent = function(id){ $(id).val(content); } ### class window.Editor extends Backbone.View el: '#editor-container' events: -> 'keypress .note-editable': 'copyToFocusedElement' #'keypress #mail-editor': 'copyToTextArea' 'drag .blocks li a' : 'drag' "dragover #bodyTable" : "displaySections" "dragleave #bodyTable" : "hideSections" "drop #bodyTable" : "hideSections" "dragover #templateBody" : "allowDrop" "dragover #templatePreheader" : "allowDrop" "dragover #templateHeader" : "allowDrop" "dragover #templateBody" : "allowDrop" "dragover #templateFooter" : "allowDrop" 'drop #templateBody': "drop" 'drop #templatePreheader': "drop" 'drop #templateHeader': "drop" 'drop #templateBody': "drop" "drop #templateFooter" : "drop" "click .tpl-block": "setFocus" "click #editor-controls #save" : "displayBlockButtons" "click .imagePlaceholder .button-small" : "displayUploaderList" "click .tpl-block-delete": "deleteBloc" initialize: -> @textarea = $(@el).find('#campaign_html_content') copyToEditor: (ev)-> $this = $(ev.currentTarget); window.setTimeout ()=> $(@el).find('#mail-editor').html($this.val()); , 0 copyToTextArea: ()-> $this = $("#mail-editor"); window.setTimeout ()=> $(@el).find('textarea').val($this.html()); , 0 copyToFocusedElement: (ev)-> console.log "soji" @currentFocused().find('.mcnTextContent').html($(ev.currentTarget).html()) @copyToTextArea() template: -> '

dsfsd

' render: -> #$(@el).find('#mail-editor').html(@template()) $(@el).find('#mail-editor').html(@textarea.val()); #init from saved content #$(@el).find('#mail-editor').html(@baseTemplate()) #init from base js tamplarte displaySections: ()-> $('.tpl-container').addClass("over") _.each $('.tpl-container'), (n)-> return if $(n).find(".legend").length > 0 $(n).append("
#{$(n).attr("mc:container")}
") hideSections: ()-> $('.tpl-container').removeClass("over") _.each $('.tpl-container'), (n)-> $(n).find(".legend").remove() drag: (ev)-> #console.log(ev) @dragged = $(ev.currentTarget) allowDrop: (ev)-> console.log("allos drop") ev.preventDefault() drop: (ev)-> ev.preventDefault() #console.log($(ev.dataTransfer.getData("text"))) console.log(@dragged.data('block'), ev.target.id) #data = $(ev.dataTransfer.getData("text")); #ev.target.appendChild(data); container = $(ev.currentTarget) tmpl = @handleBlock @dragged.data('block') container.find(".tpl-container").append(tmpl) $(container).find('.mojoMcContainerEmptyMessage').hide() @copyToTextArea() displayWysiwyg: -> $('.block-settings').show() $('.main-settings').hide() @initWysiwyg() false displayBlockButtons: -> $('.block-settings').hide() $('.main-settings').show() false currentFocused: ()-> $(".tpl-block.focus") setFocus: (ev)-> $(".tpl-block").removeClass("focus") $(ev.currentTarget).addClass("focus") @displayWysiwyg() false initWysiwyg: -> $('.summernote').destroy() InitSummernote() $('.summernote').code(@currentFocused().find('.mcnTextContent').html()); #edit = ()-> # $('.click2edit').summernote({ focus: true }); handleBlock: (block_type)-> html = "" switch block_type when "boxed" html = @boxedBlock() when "text" html = @textBlock() when "separator" html = @separatorBlock() when "image" html = @imageBlock() when "image_group" html = @imageGroupBlock() when "image_card" html = @imageCardBlock() else console.log "Nada" @wrapBlock(html) deleteBloc: (ev)-> target = $(ev.currentTarget) container = target.parents(".tpl-container") target.parents(".tpl-block").remove() if container.find(".tpl-block").length is 0 container.find(".mojoMcContainerEmptyMessage").show() false wrapBlock: (content)-> "
#{content}
#{@templateBlockControls()}
" templateBlockControls: -> "
" baseTemplate: ()-> "
Drop Content Blocks Here
Drop Content Blocks Here
Drop Content Blocks Here
Drop Content Blocks Here
#{@wrapBlock(@subscriptionBlock())}
" boxedBlock: ()-> "
This is a Text Block. Use this to provide text...
" textBlock: ()-> "
This is a Text Block. Use this to provide text...
" separatorBlock: ()-> "
" imageBlock: ()-> "
Drop an image here
or
" imageGroupBlock: ()-> "
Drop an image here
or
Drop an image here
or
" imageCardBlock: ()-> "
Drop an image here
or
Your text caption goes here
" subscriptionBlock: ()-> "
© {{campaign_description}}

Our mailing address is:
{{campaign_url}}

unsubscribe from this list    update subscription preferences 

" displayUploaderList: (ev)-> placeholder = $(ev.currentTarget).parents('.imagePlaceholder') @checkExistentImages(placeholder) false checkExistentImages: (placeholder)-> #@targetForUpload = $(ev.currentTarget) $.ajax url: $("#editor-container").data("attachments-path") dataType: "json" success: (data)=> Chaskiq.Helpers.showModal(@templateForAttachments(data), "dsdsda") _this = this $('.image-selector').on "click", ()-> html = placeholder.parents(".mcpreview-image-uploader") url = $(this).data('image-url') _this.replaceImagePreview(html, url ) false error: (err)-> alert("error retrieving files") replaceImagePreview: (html_to_replace, url)-> html_to_replace.replaceWith( "" ); Chaskiq.Helpers.hideModal() @copyToTextArea() templateForAttachments: (data)-> html = ""