chocolate
Version:
A full stack Node.js web framework built using Coffeescript
1,292 lines (1,246 loc) • 174 kB
JavaScript
// Generated by CoffeeScript 1.12.6
(function() {
var Chocodown, Chocokup, Highlight, Newnotes, _, _module,
hasProp = {}.hasOwnProperty,
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
_ = require('./chocodash');
Chocokup = require('./chocokup');
Highlight = require('./highlight');
Chocodown = require('./chocodown');
Newnotes = (function() {
_Class.kup = function() {
var base, css_class, id, newnotes_filter, newnotes_filter_list, newnotes_list, newnotes_log_buttons, newnotes_note_action, newnotes_note_attributes, newnotes_note_history, newnotes_note_input, newnotes_note_memory, newnotes_note_message, newnotes_search, ref;
id = Newnotes.panels.length;
if ((base = this.params).taste == null) {
base.taste = '';
}
style("#newnotes-" + id + "-note-panel > div {\n line-height:1.1em;\n}\n\n#newnotes-" + id + "-note-panel code {\n display: inline-block;\n margin-left: 24px;\n}\n\n#newnotes-" + id + "-note-panel ul {\n margin-left: 0;\n padding-left: 1em;\n}\n\n#newnotes-" + id + "-filter-list-body {\n margin: 10px;\n font-size: 0.8em;\n line-height: 1.4em;\n}\n\n#newnotes-" + id + "-note-panel li.note {\n list-style: none;\n line-height: 1.5em;\n}\n\n#newnotes-" + id + "-note-panel li {\n list-style: disc;\n list-style-position: inside;\n line-height: 1.15em;\n}\n \n#newnotes-" + id + "-note-panel li, #newnotes-" + id + "-filter-list-body div {\n cursor: pointer;\n padding: 0.4em 0;\n}\n\n#newnotes-" + id + "-note-panel li.compacted {\n overflow: hidden;\n}\n\n#newnotes-" + id + "-note-panel li.compacted p,\n#newnotes-" + id + "-note-panel li.compacted p + * {\n display:none;\n}\n\n#newnotes-" + id + "-note-panel > .fullscreen-narrow {\n font-size:1.4em;\n}\n\n#newnotes-" + id + "-list-panel {\n margin: 0;\n padding: 1em;\n}\n\n#newnotes-" + id + "-note-panel select {\n font-size: 0.8em;\n}\n\n#newnotes-" + id + "-filter-input {\n width: 60%;\n padding: 4px 10px 4px;\n font-style: italic;\n border: none;\n font-size: 12px;\n -moz-border-radius: 12px;\n -webkit-border-radius: 12px;\n -moz-box-shadow: inset 1px 1px 2px #bbb;\n -webkit-box-shadow: inset 1px 1px 2px #bbb;\n box-shadow: inset 1px 1px 2px #bbb;\n color: #999;\n}\n\n" + (!this.params.inherit_selected_class ? '#newnotes-' + id + '-note-panel li.selected {background-color:rgba(0,0,0,0.1);}' : '') + "\n\n.newnotes-priority-Now {\n color:red;\n}\n.newnotes-priority-Tomorrow {\n color:gold;\n}\n.newnotes-priority-Later {\n color:skyblue;\n}\n.newnotes-priority-Done {\n color:lawngreen;\n}\n.newnotes-filtered {\n background-color: gold;\n color: black;\n}\n\n#newnotes-" + id + "-note-panel .leather, #newnotes-" + id + "-note-panel .leather a, #newnotes-" + id + "-note-panel .leather select {\n background-color: #262626;\n color: rgb(165, 164, 151);\n text-shadow: 0 1px 3px rgba(171, 128, 112, 0.5) , 0 -2px 4px rgb(0, 0, 0);\n font-size: 14pt;\n font-family: Comic Sans MS;\n}\n#newnotes-" + id + "-note-panel .leather select {\n font-size: 0.8em;\n}\n#newnotes-" + id + "-note-panel .leather a {\n border: 1px solid rgb(26, 23, 23);\n border-radius: 8px;\n padding: 0px 10px 0px 8px;\n box-shadow: inset 2px 2px 12px rgb(19, 17, 17);\n text-decoration:none;\n}\n#newnotes-" + id + "-note-panel .leather > .sizer {\n border: 1px dashed rgba(60, 66, 53, 1);\n outline: 1px dashed rgba(171, 128, 112, 0.7);\n margin: 6px;\n}\n#newnotes-" + id + "-note-panel .stitch > .sizer {\n margin: 6px;\n}\n\n#newnotes-" + id + "-note-panel .paper {\n background-color: rgb(245, 242, 209);\n color: rgb(85, 78, 75);\n text-shadow: none;\n border-right: 6px double rgb(202, 195, 181);\n border-top-right-radius: 10px;\n border-bottom-right-radius: 10px;\n border-left: 2px solid rgb(119, 118, 112);\n font-size: 12pt;\n border-bottom: 1px solid black;\n background: -webkit-linear-gradient(top, rgb(228, 228, 228) 0%, rgb(245, 242, 209) 8%) 0 57px;\n background: -moz-linear-gradient(top, rgb(228, 228, 228) 0%, rgb(245, 242, 209) 8%) 0 57px;\n background: linear-gradient(top, rgb(228, 228, 228) 0%, rgb(245, 242, 209) 8%) 0 57px;\n -webkit-background-size: 100% 30px;\n -moz-background-size: 100% 30px;\n -ms-background-size: 100% 30px;\n background-size: 100% 30px;\n background-position-y: 12px;\n background-attachment: local;\n}\n\n#newnotes-" + id + "-note-panel .paper.disconnected {\n background: rgb(219, 219, 219);\n}\n\n#newnotes-" + id + "-note-panel .white-paper {\n background-color: rgb(247, 246, 232);\n border-radius: 14px;\n padding: 10px;\n color: rgb(85, 78, 75);\n text-shadow: none;\n font-size: 12pt;\n background: -webkit-linear-gradient(top, rgb(228, 228, 228) 0%, rgb(247, 246, 232) 8%) 0 57px;\n background: -moz-linear-gradient(top, rgb(228, 228, 228) 0%, rgb(247, 246, 232) 8%) 0 57px;\n background: linear-gradient(top, rgb(228, 228, 228) 0%, rgb(247, 246, 232) 8%) 0 57px;\n -webkit-background-size: 100% 30px;\n -moz-background-size: 100% 30px;\n -ms-background-size: 100% 30px;\n background-size: 100% 30px;\n background-position-y: 12px;\n background-attachment: local;\n}");
style(this.params.code_css);
css_class = (ref = this.params.box_css_class) != null ? ref : '';
if (css_class !== '') {
css_class = '.' + css_class;
}
newnotes_list = function() {
return body("#newnotes-" + id + "-list-main", function() {
return box('#.' + css_class, function() {
return body("#newnotes-" + id + "-list-body.paper", function() {
return ul("#newnotes-" + id + "-list-panel", '');
});
});
});
};
newnotes_filter = function() {
return div(function() {
a({
href: '#',
onclick: "Newnotes.panels[" + id + "].stop_filter();"
}, 'Find');
text(' : ');
input("#newnotes-" + id + "-filter-input", {
onkeyup: "Newnotes.panels[" + id + "].on_key_filter(this);",
onfocus: "Newnotes.panels[" + id + "].on_filter_focus(this);"
});
return a({
href: '#',
onclick: "Newnotes.panels[" + id + "].init_filter();"
}, 'Clear');
});
};
newnotes_filter_list = function(options) {
var hidden;
hidden = (options != null ? options.hidden : void 0) ? '.hidden' : '';
return body(("#newnotes-" + id + "-filter-list-main") + hidden, function() {
return box('#.' + css_class, function() {
return body("#newnotes-" + id + "-filter-list-body.white-paper", function() {});
});
});
};
newnotes_search = function() {
var add_selector, name, ref1, results;
add_selector = (function(_this) {
return function(name) {
return select(("#newnotes-" + id + "-search-" + (name.toLowerCase()) + "-select") + css_class, {
onchange: "Newnotes.panels[" + id + "].on_search_option_selected('" + name + "', this);"
}, '');
};
})(this);
span('#', function() {
text('Pin');
select(("#newnotes-" + id + "-pin-mode") + css_class, {
onchange: "Newnotes.panels[" + id + "].on_pin_mode_changed(this);"
}, function() {
option('on');
return option('off');
});
span(': ');
span("#newnotes-" + id + "-pin-list", function() {
return 'None';
});
return a({
href: '#',
onclick: "Newnotes.panels[" + id + "].pin();"
}, '+');
});
ref1 = Newnotes.Dimensions;
results = [];
for (name in ref1) {
if (!hasProp.call(ref1, name)) continue;
results.push(add_selector(name));
}
return results;
};
newnotes_note_action = function() {
div(function() {
a({
href: '#',
onclick: "Newnotes.panels[" + id + "].move(-1);"
}, '▲');
a({
href: '#',
onclick: "Newnotes.panels[" + id + "].dent('out');"
}, '◄');
a({
href: '#',
onclick: "Newnotes.panels[" + id + "].home();"
}, 'Home');
a({
href: '#',
onclick: "Newnotes.panels[" + id + "].new();"
}, 'New');
a({
href: '#',
onclick: "Newnotes.panels[" + id + "].sort();"
}, 'Sort');
a({
href: '#',
onclick: "Newnotes.panels[" + id + "].dent('in');"
}, '►');
return a({
href: '#',
onclick: "Newnotes.panels[" + id + "].move(1);"
}, '▼');
});
return div(function() {
a({
href: '#',
onclick: "Newnotes.panels[" + id + "].open();"
}, 'Develop');
a({
href: '#',
onclick: "Newnotes.panels[" + id + "].close();"
}, 'Open');
a({
href: '#',
onclick: "Newnotes.panels[" + id + "].toggle();"
}, 'Toggle');
a({
href: '#',
onclick: "Newnotes.panels[" + id + "].compact();"
}, 'Compact');
return a({
href: '#',
onclick: "Newnotes.panels[" + id + "].expand();"
}, 'Expand');
});
};
newnotes_note_attributes = function() {
var add_selector, name, ref1, results;
add_selector = (function(_this) {
return function(name) {
return select(("#newnotes-" + id + "-" + (name.toLowerCase()) + "-select") + css_class, {
onchange: "Newnotes.panels[" + id + "].on_option_selected('" + name + "', this);"
}, '');
};
})(this);
ref1 = Newnotes.Dimensions;
results = [];
for (name in ref1) {
if (!hasProp.call(ref1, name)) continue;
results.push(add_selector(name));
}
return results;
};
newnotes_note_input = function() {
return span(function() {
return (this.params.use_ace ? panel : textarea)("#newnotes-" + id + "-note-text-input", {
style: 'background-color:white;width:0;height:0;',
'data-ace-theme': this.params.ace_theme
}, '');
});
};
newnotes_note_history = function() {
return div("#newnotes-" + id + "-history-body", function() {});
};
newnotes_note_memory = function() {
return div("#newnotes-" + id + "-note-memory", function() {
return text(' ');
});
};
newnotes_note_message = function() {
return body("#newnotes-" + id + "-note-message", function() {
return text(' ');
});
};
newnotes_log_buttons = function(options) {
return div({
style: ((options != null ? options.float : void 0) === true ? "float:right;" : "")
}, function() {
input("#newnotes-" + id + "-note-logoff.hidden", {
type: 'button',
onclick: "Newnotes.panels[" + id + "].logoff();",
value: 'Logoff',
style: "background-color:green; color:white;"
});
return input("#newnotes-" + id + "-note-logon.hidden", {
type: 'button',
onclick: "Newnotes.panels[" + id + "].switch_login(true);",
value: 'Logon',
style: "background-color:red; color:white;"
});
});
};
panel("#newnotes-" + id + "-login-panel.hidden", function() {
return form(function() {
text('Enter your key: ');
input("#newnotes-" + id + "-login-key", {
type: 'password'
}, '');
return input({
type: 'submit',
onclick: "Newnotes.panels[" + id + "].register_key(); return false;",
value: 'Enter'
});
});
});
return panel("#newnotes-" + id + "-note-panel", function() {
body("#." + this.params.taste, function() {
switch (this.params.taste) {
case 'fullscreen-wide':
this.params.in_list = true;
box("#.leather", function() {
return box("#.stitch", function() {
return panel({
proportion: 'served'
}, function() {
panel(function() {
header({
by: 5
}, function() {
newnotes_filter();
newnotes_search();
return newnotes_note_memory();
});
return body(function() {
return newnotes_filter_list();
});
});
box(function() {
return panel(function() {
return newnotes_list();
});
});
return panel(function() {
header({
by: 10
}, function() {
newnotes_log_buttons({
float: true
});
newnotes_note_action();
return newnotes_note_attributes();
});
return body(function() {
return panel({
proportion: 'half-served',
orientation: 'vertical'
}, function() {
panel(function() {
return newnotes_note_history();
});
return panel(function() {
return newnotes_note_message();
});
});
});
});
});
});
});
return newnotes_note_input();
case 'fullscreen-narrow':
this.params.in_list = true;
panel('#.hidden', function() {
newnotes_search();
return newnotes_note_memory();
});
box("#.leather", function() {
return box("#.stitch", function() {
return panel(function() {
header(function() {
return newnotes_filter();
});
return body(function() {
return panel({
proportion: 'half-served',
orientation: 'vertical'
}, function() {
box(function() {
return panel(function() {
newnotes_filter_list({
hidden: true
});
return newnotes_list();
});
});
return panel(function() {
header({
by: 2
}, function() {
return newnotes_note_action();
});
return footer(function() {
return newnotes_log_buttons();
});
});
});
});
});
});
});
panel('#.hidden', function() {
return newnotes_note_attributes();
});
return newnotes_note_input();
default:
this.params.in_list = false;
return panel({
orientation: 'vertical',
proportion: 'half-served'
}, function() {
panel(function() {
header({
by: 3
}, function() {
return body(function() {
newnotes_filter();
newnotes_search();
return newnotes_note_memory();
});
});
newnotes_filter_list({
hidden: true
});
return newnotes_list();
});
return panel(function() {
header({
by: 3
}, function() {
return box(function() {
return body(function() {
newnotes_note_action();
return newnotes_note_attributes();
});
});
});
return body(function() {
return box('#.' + css_class, function() {
return body(function() {
return newnotes_note_input(true);
});
});
});
});
});
}
});
script('_id = ' + id + ';' + '_url = ' + JSON.stringify(this.params.url) + ';' + '_in_list = ' + this.params.in_list + ';' + '_has_keyboard = ' + this.params.has_keyboard + ';' + '_use_ace = ' + this.params.use_ace + ';' + '_standalone = ' + this.params.standalone + ';');
return coffeescript(function() {
return Newnotes.panels.push(new Newnotes.HtmlPanel(new Newnotes, _id, _url, _in_list, _has_keyboard, _use_ace, _standalone));
});
});
};
_Class.Dimensions = {
Priority: {
values: ['Now', 'Tomorrow', 'Later', 'Done']
},
Scope: {
values: ['Me', 'Household', 'Family', 'Friends', 'Community', 'Business', 'State', 'Public'],
node: 'free'
},
Action: {
values: ['Explore', 'Memorize', 'Learn', 'Teach', 'Discuss', 'Do', 'Control', 'Delegate', 'Relax'],
node: 'free'
},
Intention: {
values: ['Know', 'Use', 'Make', 'Manage'],
node: 'free'
},
Wish: {
values: ['No wish', 'Identity', 'Hobbies', 'Education', 'Religion', 'Leisure'],
node: 'free'
},
Need: {
values: ['No need', 'Food', 'Health', 'Clothing', 'Equipment', 'Housing'],
node: 'free'
},
Share: {
values: ['No share', 'Communication', 'Partnership', 'Work', 'Finance', 'Insurance'],
node: 'free'
}
};
_Class.HtmlPanel = (function() {
function _Class(newnotes1, id1, url, in_list, has_keyboard, use_ace, standalone) {
var Mode, ace_theme, cache, commands, input_box, ref, start;
this.newnotes = newnotes1;
this.id = id1;
this.url = url;
this.in_list = in_list;
this.has_keyboard = has_keyboard;
this.use_ace = use_ace;
this.standalone = standalone;
this.switch_login = bind(this.switch_login, this);
this.editor = new ((function() {
function _Class() {}
_Class.prototype.get = function() {
if (this.use_ace) {
return this._.getSession().getValue();
} else {
return this._.get('value');
}
};
_Class.prototype.set = function(value) {
if (this.use_ace) {
return this._.getSession().setValue(value);
} else {
return this._.set('value', value);
}
};
_Class.prototype.focus = function() {
this._.focus();
if (this.use_ace) {
return this._.selectAll();
} else {
return this._.select();
}
};
_Class.prototype.clear = function() {
this.current_id = void 0;
this.tree_states = {};
return this.tree_navigate = {};
};
_Class.prototype.current_id = void 0;
_Class.prototype.tree_states = {};
_Class.prototype.tree_navigate = {};
_Class.prototype.exporting = false;
_Class.prototype.modified = false;
_Class.prototype.waiting = false;
_Class.prototype.editing = false;
DOMEvent.defineKeys({
'36': 'home',
'35': 'end'
});
return _Class;
})());
if (this.use_ace) {
this.editor.use_ace = true;
this.editor._ = ace.edit("newnotes-" + this.id + "-note-text-input");
this.editor._.setShowPrintMargin(false);
this.editor._.renderer.setShowGutter(false);
input_box = document.id("newnotes-" + this.id + "-note-text-input");
ace_theme = (ref = input_box.attributes['data-ace-theme']) != null ? ref.value : void 0;
if (ace_theme != null) {
this.editor._.setTheme(ace_theme);
}
Mode = require('ace/mode/markdown').Mode;
this.editor._.getSession().setMode(new Mode());
this.editor._.getSession().on('change', (function(_this) {
return function(e) {
if (!_this.editor.editing) {
return;
}
return _this[_this.editor.current_id != null ? 'save' : 'add'](!_this.in_list);
};
})(this));
this.editor._.on('focus', (function(_this) {
return function(e) {
if (_this.editor._.container.getStyle('width') !== '0px') {
return _this.editor.editing = true;
}
};
})(this));
this.editor._.on('blur', (function(_this) {
return function(e) {
return _this.editor.editing = false;
};
})(this));
this.editor._.getSession().setUseWrapMode(true);
this.editor._.getSession().setWrapLimitRange(null, null);
commands = this.editor._.commands;
commands.addCommand({
name: "save_or_add",
bindKey: {
win: "Return",
mac: "Return"
},
exec: (function(_this) {
return function(editor) {
var document, last_col, last_row, range;
document = editor.getSession().getDocument();
last_row = document.getLength() - 1;
last_col = document.getLine(last_row).length;
range = editor.getSelectionRange();
if (!_this.editor.editing || range.isEnd(last_row, last_col)) {
return _this["new"]();
} else {
return _this.editor._.insert('\n');
}
};
})(this)
});
commands.addCommand({
name: "save_or_add_prev",
bindKey: {
win: "Alt-Return",
mac: "Alt-Return"
},
exec: (function(_this) {
return function() {
return _this["new"]({
before: true
});
};
})(this)
});
commands.addCommand({
name: "export",
bindKey: {
win: "Ctrl-S",
mac: "Command-S"
},
exec: (function(_this) {
return function() {
return _this["export"]();
};
})(this)
});
commands.addCommand({
name: "filter",
bindKey: {
win: "Ctrl-F",
mac: "Command-F"
},
exec: (function(_this) {
return function() {
return _this.focus_filter();
};
})(this)
});
commands.addCommand({
name: "indent",
bindKey: {
win: "Tab",
mac: "Tab"
},
exec: (function(_this) {
return function(editor) {
var range;
range = editor.getSelectionRange();
if (range.isStart(0, 0)) {
_this.dent('in');
return editor.focus();
} else {
return editor.indent();
}
};
})(this),
multiSelectAction: "forEach"
});
commands.addCommand({
name: "outdent",
bindKey: {
win: "Shift-Tab",
mac: "Shift-Tab"
},
exec: (function(_this) {
return function(editor) {
var range;
range = editor.getSelectionRange();
if (range.isStart(0, 0)) {
_this.dent('out');
return editor.focus();
} else {
return editor.blockOutdent();
}
};
})(this),
multiSelectAction: "forEach"
});
commands.addCommand({
name: "home",
bindKey: {
win: "Home",
mac: "Home"
},
exec: (function(_this) {
return function(editor, args) {
_this.home();
return editor.focus();
};
})(this)
});
commands.addCommand({
name: "gotoleft",
bindKey: {
win: "Left",
mac: "Left|Ctrl-B"
},
exec: (function(_this) {
return function(editor, args) {
if (!_this.editor.editing) {
_this.modify();
return _this.editor.focus();
} else {
return editor.navigateLeft(args.times);
}
};
})(this),
multiSelectAction: "forEach",
readOnly: true
});
commands.addCommand({
name: "gotoright",
bindKey: {
win: "Right",
mac: "Right|Ctrl-F"
},
exec: (function(_this) {
return function(editor, args) {
if (!_this.editor.editing) {
_this.modify();
return _this.editor.focus();
} else {
return editor.navigateRight(args.times);
}
};
})(this),
multiSelectAction: "forEach",
readOnly: true
});
commands.addCommand({
name: "golineup",
bindKey: {
win: "Up",
mac: "Up|Ctrl-P"
},
exec: (function(_this) {
return function(editor, args) {
var range;
range = editor.getSelectionRange();
if (range.isStart(0, 0)) {
return _this.navigate(-1);
} else {
return editor.navigateUp(args.times);
}
};
})(this),
multiSelectAction: "forEach",
readOnly: true
});
commands.addCommand({
name: "golinedown",
bindKey: {
win: "Down",
mac: "Down|Ctrl-N"
},
exec: (function(_this) {
return function(editor, args) {
var document, last_col, last_row, range;
document = editor.getSession().getDocument();
last_row = document.getLength() - 1;
last_col = document.getLine(last_row).length;
range = editor.getSelectionRange();
if (range.isEnd(last_row, last_col)) {
return _this.navigate(1);
} else {
return editor.navigateDown(args.times);
}
};
})(this),
multiSelectAction: "forEach",
readOnly: true
});
commands.addCommand({
name: "movelineup",
bindKey: {
win: "Ctrl-Up",
mac: "Ctrl-Up"
},
exec: (function(_this) {
return function(editor, args) {
_this.move(-1);
editor.focus();
return true;
};
})(this)
});
commands.addCommand({
name: "movelinedown",
bindKey: {
win: "Ctrl-Down",
mac: "Ctrl-Down"
},
exec: (function(_this) {
return function(editor, args) {
_this.move(1);
editor.focus();
return true;
};
})(this)
});
commands.addCommand({
name: "compact",
bindKey: {
win: "Ctrl-Shift-Up",
mac: "Ctrl-Shift-Up"
},
exec: (function(_this) {
return function(editor, args) {
_this.open();
editor.focus();
return true;
};
})(this)
});
commands.addCommand({
name: "expand",
bindKey: {
win: "Ctrl-Shift-Down",
mac: "Ctrl-Shift-Down"
},
exec: (function(_this) {
return function(editor, args) {
_this.close();
editor.focus();
return true;
};
})(this)
});
commands.addCommand({
name: "clear_filter",
bindKey: {
win: "Esc",
mac: "Esc"
},
exec: (function(_this) {
return function(editor, args) {
_this.clear_filter();
return editor.focus();
};
})(this)
});
commands.addCommand({
name: "togglepriority_or_split_node_or_newline",
bindKey: {
win: "Ctrl-Return",
mac: "Ctrl-Return"
},
exec: (function(_this) {
return function(editor, args) {
var document, last_col, last_row, range;
if (!_this.editor.editing) {
_this.toggle_priority();
return editor.focus();
} else {
document = editor.getSession().getDocument();
last_row = document.getLength() - 1;
last_col = document.getLine(last_row).length;
range = editor.getSelectionRange();
if (!range.isEnd(last_row, last_col)) {
_this.split();
return editor.focus();
} else {
return _this.editor._.insert('\n');
}
}
};
})(this)
});
commands.addCommand({
name: "toggle_or_newline",
bindKey: {
win: "Shift-Return",
mac: "Shift-Return"
},
exec: (function(_this) {
return function(editor, args) {
var document, last_col, last_row, range;
document = editor.getSession().getDocument();
last_row = document.getLength() - 1;
last_col = document.getLine(last_row).length;
range = editor.getSelectionRange();
if (range.isStart(0, 0) && range.isEnd(last_row, last_col)) {
_this.toggle();
_this.list();
editor.focus();
return true;
} else {
return _this.editor._.insert('\n');
}
};
})(this)
});
commands.addCommand({
name: "pin",
bindKey: {
win: "Ctrl-Shift-Return",
mac: "Ctrl-Shift-Return"
},
exec: (function(_this) {
return function(editor, args) {
if (!_this.editor.editing) {
_this.pin();
return editor.focus();
}
};
})(this)
});
} else {
this.editor.use_ace = false;
this.editor._ = document.id("newnotes-" + this.id + "-note-text-input");
this.editor._.addEvent('keyup', (function(_this) {
return function(e) {
if (!_this.editor.editing) {
return;
}
return _this[_this.editor.current_id != null ? 'save' : 'add'](false);
};
})(this));
this.editor._.addEvent('focus', (function(_this) {
return function(e) {
if (_this.editor._.container.getStyle('width') !== '0px') {
return _this.editor.editing = true;
}
};
})(this));
this.editor._.addEvent('blur', (function(_this) {
return function(e) {
_this.editor.editing = false;
return _this.list();
};
})(this));
this.editor._.container = this.editor._;
this.editor._.container.dispose();
}
start = (function(_this) {
return function() {
_this.check_connected();
setInterval((function() {
return _this.check_connected();
}), 1 * 60 * 1000);
return _this.reload();
};
})(this);
cache = window.applicationCache;
if (this.standalone) {
window.addEventListener('load', function(e) {
cache.addEventListener('updateready', function(e) {
if (cache.status === cache.UPDATEREADY) {
cache.swapCache();
return window.location.reload();
} else {
}
}, false);
cache.addEventListener('cached', (function(e) {
return start();
}), false);
cache.addEventListener('noupdate', (function(e) {
return start();
}), false);
return cache.addEventListener('error', (function(e) {
return start();
}), false);
}, false);
} else {
start();
}
}
_Class.prototype.current_get = function() {
return this.newnotes.data.by.id[this.editor.current_id];
};
_Class.prototype.current_set = function(id) {
var note, results;
this.editor.current_id = id;
this.newnotes.path = [];
if (id != null) {
note = this.newnotes.data.by.id[id];
this.newnotes.path.push(id);
results = [];
while ((note = note.parent) != null) {
results.push(this.newnotes.path.unshift(note.uuid));
}
return results;
}
};
_Class.prototype.register_key = function() {
var ref;
if (((ref = this.url) != null ? ref.register_key : void 0) != null) {
return new Request({
data: {
key: document.id("newnotes-" + this.id + "-login-key").value
},
noCache: true,
url: this.url.register_key,
onSuccess: (function(_this) {
return function(data) {
_this.switch_login(false);
return _this.check_connected();
};
})(this),
onFailure: function(xhr) {}
}).post();
}
};
_Class.prototype.logoff = function() {
var ref;
if (((ref = this.url) != null ? ref.forget_keys : void 0) != null) {
return new Request({
url: this.url.forget_keys,
noCache: true,
onSuccess: (function(_this) {
return function(data) {
_this.switch_login(true);
return _this.check_connected();
};
})(this),
onFailure: function(xhr) {}
}).post();
}
};
_Class.prototype.switch_login = function(switched) {
if (document.id("newnotes-" + this.id + "-" + (switched === true ? 'login' : 'note') + "-panel").hasClass('hidden')) {
document.id("newnotes-" + this.id + "-note-panel")[(switched === true ? 'add' : 'remove') + "Class"]('hidden');
document.id("newnotes-" + this.id + "-login-panel")[(switched === true ? 'remove' : 'add') + "Class"]('hidden');
if (!switched) {
return this.reload();
}
}
};
_Class.prototype.data_modified_date = void 0;
_Class.prototype.get_data_modified_date = function() {
if (this.is_connected) {
return new Request({
url: this.url.modified_date,
noCache: true,
onSuccess: (function(_this) {
return function(responseText) {
var value;
if (responseText !== '') {
value = parseInt(responseText);
if (_this.data_modified_date == null) {
_this.data_modified_date = value;
}
if (value > _this.data_modified_date) {
_this.data_modified_date = value;
return window.location.reload();
}
}
};
})(this),
onFailure: function(xhr) {}
}).get();
}
};
_Class.prototype.is_connected = false;
_Class.prototype.check_connected = function() {
var ref, switch_log;
switch_log = (function(_this) {
return function(switched) {
_this.is_connected = !switched;
document.id("newnotes-" + _this.id + "-note-log" + (switched === true ? 'on' : 'off')).removeClass('hidden');
document.id("newnotes-" + _this.id + "-note-log" + (switched === true ? 'off' : 'on')).addClass('hidden');
if (_this.is_connected) {
setTimeout((function() {
return _this.get_data_modified_date.call(_this);
}), 100);
}
return document.id("newnotes-" + _this.id + "-list-body")[(switched ? 'add' : 'remove') + 'Class']('disconnected');
};
})(this);
if (((ref = this.url) != null ? ref.connected : void 0) != null) {
return new Request({
url: this.url.connected,
noCache: true,
onSuccess: function(data) {
if (data === "connected") {
return switch_log(false);
} else {
return switch_log(true);
}
},
onFailure: function(xhr) {
return switch_log(true);
}
}).get();
}
};
_Class.prototype['new'] = function(option) {
var note;
this.remove_if_empty();
note = this.newnotes.add('', ((option != null ? option.at_end : void 0) ? void 0 : this.current_get()), ((option != null ? option.before : void 0) ? 0 : 1));
this.on_tagging_change(note);
this.current_set(note.uuid);
this.editor.set('');
this.on_note_modified();
return this.modify();
};
_Class.prototype.add = function() {
var note;
note = this.newnotes.add(this.editor.get());
this.on_tagging_change(note);
this.current_set(note.uuid);
this.list();
return this.on_note_modified();
};
_Class.prototype.split = function() {
var Range, del_range, del_text, document, last_col, last_row, pos;
document = this.editor._.getSession().getDocument();
last_row = document.getLength() - 1;
last_col = document.getLine(last_row).length;
pos = this.editor._.getCursorPosition();
Range = require('ace/range').Range;
del_range = new Range(pos.row, pos.column, last_row, last_col);
del_text = this.editor._.getSession().getTextRange(del_range);
this.editor._.getSession().remove(del_range);
this["new"]();
return this.editor._.setValue(del_text);
};
_Class.prototype.sort = function() {
var note;
note = this.current_get();
this.newnotes.sort(note);
this.list();
return this.on_note_modified();
};
_Class.prototype.dent = function(direction) {
var note, parent, result;
note = this.current_get();
parent = note.parent;
this.newnotes[direction + 'dent'](note);
result = [];
result.push(this.on_tagging_change(note));
if (parent != null) {
result.push(this.on_tagging_change(parent, true));
}
if (indexOf.call(result, true) < 0) {
this.list();
return this.on_note_modified();
}
};
_Class.prototype.move = function(step) {
this.newnotes.move(this.current_get(), step);
this.list();
return this.on_note_modified();
};
_Class.prototype.remove_if_empty = function() {
var note;
note = this.current_get();
if ((note != null ? note.title : void 0) === '' && note.subs.length === 0) {
this.newnotes.remove(note);
this.on_tagging_change(note);
this.newnotes.path = [];
this.on_note_modified();
return true;
} else {
return false;
}
};
_Class.prototype.set_dimension = function(option, value, note, dolist, propagate) {
if (dolist == null) {
dolist = true;
}
if (propagate == null) {
propagate = true;
}
if (note != null) {
this.save(false, option, value, note);
if (propagate) {
this.on_tagging_change(note, void 0, false);
}
this.on_note_modified();
if (dolist) {
this.list();
}
}
return this.newnotes.dimensions[option].value = value;
};
_Class.prototype.toggle_priority = function(item, index) {
var dimension, id, note, value;
id = item != null ? item.attributes['data-uuid'].value : this.current_get().uuid;
note = this.newnotes.data.by.id[id];
if ((note != null ? note.subs.length : void 0) > 0) {
return;
}
dimension = 'Priority';
if (index == null) {
index = Newnotes.Dimensions.Priority.values.indexOf(note.dimensions[dimension]) + 1;
}
if (index >= Newnotes.Dimensions[dimension].values.length) {
index = 0;
}
value = Newnotes.Dimensions[dimension].values[index];
this.set_dimension(dimension, value, note);
document.id("newnotes-" + this.id + "-" + (dimension.toLowerCase()) + "-select").value = value;
this.on_note_modified();
this.list();
return this.editor.focus();
};
_Class.prototype.save = function(dolist, option, value, note) {
if (note == null) {
note = this.current_get();
}
if (option == null) {
this.newnotes.modify(note, this.editor.get());
} else {
this.newnotes.modify(note, option, value);
}
if (dolist !== false) {
this.list();
}
if (window.event.type !== 'click') {
return this.on_note_modified();
}
};
_Class.prototype.load = function(callback) {
var ref;
if (((ref = this.url) != null ? ref.load : void 0) != null) {
return new Request.JSON({
url: this.url.load,
onSuccess: (function(_this) {
return function(data) {
var i, j, key, l, len1, len2, name, note, ref1, ref2, ref3, ref4, ref5, ref6, uuid;
if (data != null) {
ref1 = data.by.id;
for (uuid in ref1) {
if (!hasProp.call(ref1, uuid)) continue;
note = ref1[uuid];
data.by.id[uuid] = Newnotes.Note.create(note);
}
ref2 = data.by.id;
for (uuid in ref2) {
if (!hasProp.call(ref2, uuid)) continue;
note = ref2[uuid];
Newnotes.Note.awake(note, data);
}
ref3 = data.by.root;
for (i = j = 0, len1 = ref3.length; j < len1; i = ++j) {
uuid = ref3[i];
data.by.root[i] = data.by.id[uuid];
}
ref4 = Newnotes.Dimensions;
for (name in ref4) {
if (!hasProp.call(ref4, name)) continue;
ref5 = data.by[name];
for (key in ref5) {
if (!hasProp.call(ref5, key)) continue;
ref6 = data.by[name][key];
for (i = l = 0, len2 = ref6.length; l < len2; i = ++l) {
uuid = ref6[i];
data.by[name][key][i] = data.by.id[uuid];
}
}
}
_this.newnotes.data = data;
if (data.by.root.length === 0) {
_this.newnotes.add('new Note !');
}
return typeof callback === "function" ? callback() : void 0;
}
};
})(this),
onFailure: function(xhr) {}
}).get();
}
};
_Class.prototype.reload = function() {
return this.load((function(_this) {
return function() {
var name, ref;
_this.list();
_this.fill_search_selector();
ref = Newnotes.Dimensions;
for (name in ref) {
if (!hasProp.call(ref, name)) continue;
document.id("newnotes-" + _this.id + "-" + (name.toLowerCase()) + "-select").set('html', _this.html_options("" + name));
}
_this.editor._.resize();
return _this.editor.focus();
};
})(this));
};
_Class.prototype["export"] = function() {
var base, data, item, j, key, l, len1, len2, name, note, ref, ref1, ref2, ref3, ref4, ref5, uuid;
if (this.remove_if_empty()) {
this.list();
}
data = Newnotes.new_data();
ref = this.newnotes.data.by.id;
for (uuid in ref) {
if (!hasProp.call(ref, uuid)) continue;
note = ref[uuid];
data.by.id[uuid] = note["export"]();
}
ref1 = this.newnotes.data.by.root;
for (j = 0, len1 = ref1.length; j < len1; j++) {
item = ref1[j];
data.by.root.push(item.uuid);
}
ref2 = Newnotes.Dimensions;
for (name in ref2) {
if (!hasProp.call(ref2, name)) continue;
ref3 = this.newnotes.data.by[name];
for (key in ref3) {
if (!hasProp.call(ref3, key)) continue;
ref4 = this.newnotes.data.by[name][key];
for (l = 0, len2 = ref4.length; l < len2; l++) {
item = ref4[l];
((base = data.by[name])[key] != null ? base[key] : base[key] = []).push(item.uuid);
}
}
}
if (((ref5 = this.url) != null ? ref5.save : void 0) != null) {
this.editor.exporting = true;
return new Request.JSON({
url: this.url.save,
onSuccess: (function(_this) {
return function() {
_this.editor.exporting = false;
_this.data_modified_date = void 0;
return setTimeout((function() {
return _this.get_data_modified_date.call(_this);
}), 100);
};
})(this),
onFailure: function(xhr) {}
}).post(JSON.stringify(data));
}
};
_Class.prototype.display_message = function(message) {
return new Element('div').set('html', ('<p>' + new Date().toString('dd/MM/yyyy HH:mm:ss')) + '<br/> ' + message + '</p>').inject(document.id("newnotes-" + this.id + "-note-message"), 'top');
};
_Class.prototype.list = function() {
var is_editing, kup, line_count, line_height, list_body, list_panel, new_element, new_height, ref, ref1, scroll_pos;
kup = function() {
var nav;
nav = this.params.editor.tree_navigate;
nav.previous = nav.current = nav.next = void 0;
kup = function(selection) {
var base, bullet, bullet_char, classes, compacted_title, index, is_compacted, item, j, len1, name1, priority, regexp, results, selected, state, str_content, str_title;
if (selection == null) {
selection = this.params.selection;
}
if (this.params.filter.text != null) {
if (selection.filtered.first != null) {
if (this.params.filter.last_filter !== this.params.filter.text) {
this.params.editor.current_id = this.params.fi