{I"
class:ETI"BundledAsset; FI"logical_path; TI"&chaskiq/manage/campaign_wizard.js; FI"
pathname; TI"t/Users/michelsonmartinez/Documents/ruby/chaskiq/app/assets/javascripts/chaskiq/manage/campaign_wizard.js.coffee; FI"content_type; TI"application/javascript; TI"
mtime; Tl+p2UI"length; Ti ~I"digest; TI"%a0c2d24800e89c7ca89d6d0c3af60384; FI"source; TI" ~(function() {
var extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
window.Editor = (function(superClass) {
extend(Editor, superClass);
function Editor() {
return Editor.__super__.constructor.apply(this, arguments);
}
Editor.prototype.el = '#chaskiq-mail-editor';
Editor.prototype.events = function() {
return {
'keyup .note-editable': 'copyToFocusedElement',
'drag .blocks li a': 'drag',
'drag .tpl-block-controls a': 'drag',
'dragstart .tpl-block-controls a': 'setDraggedEl',
'dragend .tpl-block-controls a': 'removeDraggedEl',
"dragleave #bodyTable": "hideSections",
"drop #bodyTable": "hideSections",
"dragover .tpl-block": "displayItemOver",
"dragover .chaskiqContainerEmptyMessage": "displayItemOver",
'drop #templateBody': "drop",
'drop #templatePreheader': "drop",
'drop #templateHeader': "drop",
'drop #templateBody': "drop",
"drop #templateFooter": "drop",
"click .tpl-block": "setFocus",
"click #editor-controls #save": "saveAndClose",
"click .imagePlaceholder .button-small": "displayUploaderList",
"click .tpl-block-delete": "deleteBloc",
"changeColor.colorpicker .colorpicker": "changeColor",
"change .text-size-picker": "changeProperty",
"change .font-picker": "changeProperty",
"change .font-weight": "changeProperty",
"change .font-spacing": "changeProperty",
"change .font-align": "changeProperty",
"click input.submit": "submitEditor"
};
};
Editor.prototype.initialize = function() {
this.textarea = $(this.el).find('#campaign_html_content');
return this.css = $(this.el).find('#campaign_css');
};
Editor.prototype.copyToEditor = function(ev) {
var $this;
$this = $(ev.currentTarget);
return window.setTimeout((function(_this) {
return function() {
return $(_this.el).find('#mail-editor').html($this.val());
};
})(this), 0);
};
Editor.prototype.copyToTextArea = function() {
var $this;
$this = $("#mail-editor");
return window.setTimeout((function(_this) {
return function() {
return $(_this.el).find('#campaign_html_content').val($this.html());
};
})(this), 0);
};
Editor.prototype.copyToFocusedElement = function(ev) {
this.currentFocused().find('.mcnTextContent').html($(ev.currentTarget).html());
return this.copyToTextArea();
};
Editor.prototype.copyCssRulesToTextArea = function() {
var rules;
rules = _.map(this.style().cssRules, function(rule) {
return rule.cssText;
});
return $("#campaign_css").val(rules.join(" "));
};
Editor.prototype.submitEditor = function(ev) {
this.removeTplBlockControls();
this.copyToTextArea();
this.copyCssRulesToTextArea();
return setTimeout(function() {
return $(ev.currentTarget).submit();
}, 600);
};
Editor.prototype.template = function() {
return '
dsfsd
';
};
Editor.prototype.render = function() {
$(this.el).find('#mail-editor').html(this.textarea.val());
$("#tab-2").html(this.baseStylesTemplate("accordeon", this.definitionsForEditor()));
$('.colorpicker').colorpicker();
this.removeTplBlockControls();
return this.addTplBlockControls();
};
Editor.prototype.removeTplBlockControls = function() {
return $(".tpl-block-controls").remove();
};
Editor.prototype.addTplBlockControls = function() {
return _.each($(".chaskiqBlock.tpl-block"), (function(_this) {
return function(n) {
return $(n).append(_this.templateBlockControls());
};
})(this));
};
Editor.prototype.displaySections = function(ev) {
var container;
container = $(ev.currentTarget).parent(".tpl-container");
container.append("" + ($(container).attr("mc:container")) + "
");
container.addClass("default");
if (container.hasClass("tpl-container")) {
container.addClass("over").removeClass("default");
container.find(".legend").addClass("over").removeClass("default");
}
return ev.preventDefault();
};
Editor.prototype.setDraggedEl = function(e) {
this.crt = $(e.currentTarget).parents(".tpl-block")[0].cloneNode(true);
this.crt.style.backgroundColor = "white";
this.crt.style.position = "absolute";
this.crt.style.border = "1px solid #666";
this.crt.style.boxShadow = "1px 2px 2px #adadad";
this.crt.style.top = "0px";
this.crt.style.right = "0px";
this.crt.style.opacity = 0.9;
this.crt.style.zIndex = -9999;
document.body.appendChild(this.crt);
e.dataTransfer = e.originalEvent.dataTransfer;
return e.dataTransfer.setDragImage(this.crt, 0, 0);
};
Editor.prototype.removeDraggedEl = function() {
return $(this.crt).remove();
};
Editor.prototype.displayItemOver = function(ev) {
this.displaySections(ev);
$('.tpl-block').removeClass("chaskiqDndItemBefore");
if ($(ev.currentTarget).hasClass("tpl-block")) {
$(ev.currentTarget).addClass("chaskiqDndItemBefore");
}
return ev.preventDefault();
};
Editor.prototype.hideSections = function() {
$('.tpl-container').removeClass("default").removeClass("over");
return _.each($('.tpl-container'), function(n) {
return $(n).find(".legend").remove();
});
};
Editor.prototype.drag = function(ev) {
return this.dragged = $(ev.currentTarget);
};
Editor.prototype.allowDrop = function(ev) {
return ev.preventDefault();
};
Editor.prototype.displayEmptyBlocks = function() {
return _.each($('.tpl-container'), function(container) {
var empty_message;
empty_message = $(container).find('.chaskiqContainerEmptyMessage');
if ($(container).find(".tpl-block").length > 0) {
return empty_message.hide();
} else {
return empty_message.show();
}
});
};
Editor.prototype.drop = function(ev) {
var container, tmpl, to_drop;
ev.preventDefault();
console.log(ev.target.id);
container = $(ev.currentTarget);
if (this.dragged.attr('data-block')) {
tmpl = this.handleBlock(this.dragged.data('block'));
this.dropBlock(container, tmpl);
} else {
to_drop = this.dragged.parents(".tpl-block");
this.dropBlock(container, to_drop);
}
this.copyToTextArea();
this.releaseBeforeItem();
return this.displayEmptyBlocks();
};
Editor.prototype.dropBlock = function(container, tmpl) {
if ($(".tpl-block.chaskiqDndItemBefore").length > 0) {
container.find(".tpl-block.chaskiqDndItemBefore").before(tmpl);
return container.find('.chaskiqContainerEmptyMessage').hide();
} else {
return container.find(".tpl-container").append(tmpl);
}
};
Editor.prototype.releaseBeforeItem = function() {
return $(".tpl-block").removeClass("chaskiqDndItemBefore");
};
Editor.prototype.displayWysiwyg = function() {
$('.block-settings').show();
$('.main-settings').hide();
this.initWysiwyg();
return false;
};
Editor.prototype.displayBlockButtons = function() {
$('.block-settings').hide();
$('.main-settings').show();
return false;
};
Editor.prototype.saveAndClose = function() {
this.copyToTextArea();
this.displayBlockButtons();
return false;
};
Editor.prototype.currentFocused = function() {
return $(".tpl-block.focus");
};
Editor.prototype.setFocus = function(ev) {
$(".tpl-block").removeClass("focus");
$(ev.currentTarget).addClass("focus");
this.displayWysiwyg();
this.renderBlockDesignSettings();
return false;
};
Editor.prototype.initWysiwyg = function() {
$('.summernote').destroy();
InitSummernote();
return $('.summernote').code(this.currentFocused().find('.mcnTextContent').html());
};
Editor.prototype.handleBlock = function(block_type) {
var html;
html = "";
switch (block_type) {
case "boxed":
html = this.boxedBlock();
break;
case "text":
html = this.textBlock();
break;
case "separator":
html = this.separatorBlock();
break;
case "image":
html = this.imageBlock();
break;
case "image_group":
html = this.imageGroupBlock();
break;
case "image_card":
html = this.imageCardBlock();
break;
default:
console.log("Nada");
}
return this.wrapBlock(html);
};
Editor.prototype.deleteBloc = function(ev) {
var container, target;
target = $(ev.currentTarget);
container = target.parents(".tpl-container");
target.parents(".tpl-block").remove();
if (container.find(".tpl-block").length === 0) {
container.find(".chaskiqContainerEmptyMessage").show();
}
return false;
};
Editor.prototype.wrapBlock = function(content) {
return " " + content + "
" + (this.templateBlockControls()) + "
";
};
Editor.prototype.templateBlockControls = function() {
return "";
};
Editor.prototype.baseTemplate = function() {
return "";
};
Editor.prototype.boxedBlock = function() {
return " This is a Text Block. Use this to provide text... | | |
";
};
Editor.prototype.textBlock = function() {
return " This is a Text Block. Use this to provide text... | |
";
};
Editor.prototype.separatorBlock = function() {
return "";
};
Editor.prototype.imageBlock = function() {
return "";
};
Editor.prototype.imageGroupBlock = function() {
return "";
};
Editor.prototype.imageCardBlock = function() {
return " | Your text caption goes here | |
";
};
Editor.prototype.subscriptionBlock = function() {
return " © {{campaign_description}} Our mailing address is: {{campaign_url}} unsubscribe from this list update subscription preferences | |
";
};
Editor.prototype.displayUploaderList = function(ev) {
var placeholder;
placeholder = $(ev.currentTarget).parents('.imagePlaceholder');
this.checkExistentImages(placeholder);
return false;
};
Editor.prototype.checkExistentImages = function(placeholder) {
return $.ajax({
url: $("#editor-container").data("attachments-path"),
dataType: "json",
success: (function(_this) {
return function(data) {
Chaskiq.Helpers.showModal(_this.templateForAttachments(data), "dsdsda");
_this = _this;
return $('.image-selector').on("click", function() {
var html, url;
html = placeholder.parents(".mcpreview-image-uploader");
url = $(this).data('image-url');
_this.replaceImagePreview(html, url);
return false;
});
};
})(this),
error: function(err) {
return alert("error retrieving files");
}
});
};
Editor.prototype.replaceImagePreview = function(html_to_replace, url) {
html_to_replace.replaceWith("
");
Chaskiq.Helpers.hideModal();
return this.copyToTextArea();
};
Editor.prototype.templateForAttachments = function(data) {
var html;
html = "";
_.each(data, function(num) {
html += "- ";
html += "
";
html += "Select";
return html += " ";
});
return html += "
";
};
/* Style Handling */
Editor.prototype.findStyleSheet = function() {
return _.find(document.styleSheets, function(n) {
return n.ownerNode.id === "custom_style";
});
};
Editor.prototype.findRule = function(name, sheet) {
if (sheet == null) {
sheet = this.defaultStyleSheet();
}
return _.find(sheet.cssRules, function(n) {
return n.selectorText === name;
});
};
Editor.prototype.findRuleIndex = function(sheet, name) {
var indexes;
indexes = _.map(sheet.cssRules, function(n, i) {
if (n.selectorText === name) {
return i;
}
});
return indexes[0];
};
Editor.prototype.defaultStyleSheet = function() {
return this.findStyleSheet();
};
Editor.prototype.style = function() {
return this.defaultStyleSheet();
};
Editor.prototype.modifyRule = function(selector, property, value) {
var rule, s;
rule = this.findRule(selector);
s = this.style();
if (_.isUndefined(rule)) {
return s.insertRule(selector + " { property: " + value + ";}", s.cssRules.length);
} else {
return this.findRule(selector).style[property] = value;
}
};
Editor.prototype.definitionsForEditor = function() {
return [
{
name: "page",
targets: [
{
name: "background page",
selector: "#bodyTable",
template: "background"
}, {
name: "heading 1",
selector: "#bodyTable h1",
template: "typography"
}, {
name: "heading 2",
selector: "#bodyTable h2",
template: "typography"
}, {
name: "page links",
selector: "#bodyTable a",
template: "typography"
}
]
}, {
name: "preheader",
targets: [
{
name: "background pre header",
selector: "#templatePreheader",
template: "background"
}, {
name: "headings",
selector: "#templatePreHeader h1",
template: "typography"
}, {
name: "headings",
selector: "#templatePreHeader h2",
template: "typography"
}
]
}, {
name: "header",
targets: [
{
name: "header background",
selector: "#templateHeader",
template: "background"
}
]
}, {
name: "body",
targets: [
{
name: "body background",
selector: "#templateBody",
template: "background"
}, {
name: "body content text",
selector: ".bodyContainer .mcnTextContent, .bodyContainer .mcnTextContent p",
template: "typography"
}
]
}, {
name: "footer",
targets: [
{
name: "footer background",
selector: "#templateFooter",
template: "background"
}, {
name: "footer content text",
selector: ".footerContainer .mcnTextContent, .footerContainer .mcnTextContent p",
template: "typography"
}
]
}, {
name: "columns",
targets: []
}
];
};
Editor.prototype.definitionsForBlocks = function() {
return [
{
name: "mcnBaseTemplate",
targets: []
}, {
name: "mcnBoxedText",
targets: []
}, {
name: "mcnText",
targets: [
{
name: "background page",
selector: "",
template: "background"
}, {
name: "heading 1",
selector: "",
template: "typography"
}, {
name: "heading 2",
selector: "",
template: "typography"
}, {
name: "page links",
selector: "",
template: "typography"
}
]
}, {
name: "mcnDivider",
targets: []
}, {
name: "mcnImage",
targets: []
}, {
name: "mcnImageGroup",
targets: []
}, {
name: "mcnImageCard",
targets: []
}, {
name: "mcnSubscription",
targets: []
}
];
};
Editor.prototype.renderBlockDesignSettings = function() {
var focused, html, section;
focused = this.currentFocused().find("table:first").attr("class");
section = _.find(editor.definitionsForBlocks(), (function(_this) {
return function(n) {
return (n.name + "Block") === focused;
};
})(this));
console.log("section " + focused);
if (section) {
console.log("display for " + focused);
this.current_section = section;
html = this.buildDesignToolForTarget(section);
$("#tab-4").html(html);
return $('.colorpicker').colorpicker();
}
};
Editor.prototype.baseStylesTemplate = function(id, definitions) {
return " " + (this.colapsiblePanelsFor(id, definitions)) + "
";
};
Editor.prototype.colapsiblePanelsFor = function(id, style_types) {
var tpl;
tpl = _.map(style_types, (function(_this) {
return function(n) {
return " " + (_this.buildDesignToolForTarget(n)) + "
";
};
})(this));
return tpl.join(" ");
};
Editor.prototype.buildDesignToolForTarget = function(section) {
var tpl;
tpl = _.map(section.targets, (function(_this) {
return function(n) {
return _this.templateToolsFor(n);
};
})(this));
return "";
};
Editor.prototype.templateToolsFor = function(n) {
var title, tools;
title = "" + n.name + "
";
tools = "";
switch (n.template) {
case "background":
tools = this.backgroundFieldsFor(n);
break;
case "typography":
tools = this.typoFieldsFor(n);
}
return [title, tools].join(" ");
};
Editor.prototype.changeColor = function(ev) {
var css, property, value;
css = $(ev.currentTarget).data('css');
property = $(ev.currentTarget).data('css-property');
value = ev.color.toString();
console.log("changing from " + css + ", " + property + " " + value);
if (css.length > 0) {
return this.modifyRule(css, property, value);
} else {
return editor.currentFocused().find("table:first").find("." + this.current_section.name + "Content").css(property, value);
}
};
Editor.prototype.changeProperty = function(ev) {
var css, property, value;
css = $(ev.currentTarget).data('css');
property = $(ev.currentTarget).data('css-property');
value = $(ev.currentTarget).val();
console.log("changing from " + css + ", " + property + " " + value);
if (css.length > 0) {
return this.modifyRule(css, property, value);
} else {
return editor.currentFocused().find("table:first").find("." + this.current_section.name + "Content").css(property, value);
}
};
Editor.prototype.backgroundFieldsFor = function(target) {
return [""].join(" ");
};
Editor.prototype.arrayGen = function(n) {
return Array.apply(null, {
length: n
}).map(Number.call, Number);
};
Editor.prototype.typoFieldsFor = function(target) {
var align, color, familyFont, sizeFont, spacingtext, weight;
color = "";
sizeFont = "";
familyFont = "";
weight = "";
spacingtext = "";
align = "";
return [color, sizeFont, familyFont, weight, spacingtext, align].join(" ");
};
return Editor;
})(Backbone.View);
}).call(this);
; TI"required_assets_digest; TI"%cca95cdf8a138651456333b96f2f0e0b; FI"
_version; TI"%64e62ddc273c2f5847f30d698ca14b67; F