");
+ $input.on("blur.tt", function($e) {
+ var active, isActive, hasActive;
+ active = document.activeElement;
+ isActive = $menu.is(active);
+ hasActive = $menu.has(active).length > 0;
+ if (_.isMsie() && (isActive || hasActive)) {
+ $e.preventDefault();
+ $e.stopImmediatePropagation();
+ _.defer(function() {
+ $input.focus();
+ });
+ }
+ });
+ $menu.on("mousedown.tt", function($e) {
+ $e.preventDefault();
+ });
+ },
+ _onSelectableClicked: function onSelectableClicked(type, $el) {
+ this.select($el);
+ },
+ _onDatasetCleared: function onDatasetCleared() {
+ this._updateHint();
+ },
+ _onDatasetRendered: function onDatasetRendered(type, suggestions, async, dataset) {
+ this._updateHint();
+ if (this.autoselect) {
+ var cursorClass = this.selectors.cursor.substr(1);
+ this.menu.$node.find(this.selectors.suggestion).first().addClass(cursorClass);
}
+ this.eventBus.trigger("render", suggestions, async, dataset);
},
- _onCursorMoved: function onCursorMoved() {
- var datum = this.dropdown.getDatumForCursor();
- this.input.setInputValue(datum.value, true);
- this.eventBus.trigger("cursorchanged", datum.raw, datum.datasetName);
+ _onAsyncRequested: function onAsyncRequested(type, dataset, query) {
+ this.eventBus.trigger("asyncrequest", query, dataset);
},
- _onCursorRemoved: function onCursorRemoved() {
- this.input.resetInputValue();
- this._updateHint();
+ _onAsyncCanceled: function onAsyncCanceled(type, dataset, query) {
+ this.eventBus.trigger("asynccancel", query, dataset);
},
- _onDatasetRendered: function onDatasetRendered() {
- this._updateHint();
- },
- _onOpened: function onOpened() {
- this._updateHint();
- this.eventBus.trigger("opened");
- },
- _onClosed: function onClosed() {
- this.input.clearHint();
- this.eventBus.trigger("closed");
+ _onAsyncReceived: function onAsyncReceived(type, dataset, query) {
+ this.eventBus.trigger("asyncreceive", query, dataset);
},
_onFocused: function onFocused() {
- this.isActivated = true;
- this.dropdown.open();
+ this._minLengthMet() && this.menu.update(this.input.getQuery());
},
_onBlurred: function onBlurred() {
- this.isActivated = false;
- this.dropdown.empty();
- this.dropdown.close();
+ if (this.input.hasQueryChangedSinceLastFocus()) {
+ this.eventBus.trigger("change", this.input.getQuery());
+ }
},
_onEnterKeyed: function onEnterKeyed(type, $e) {
- var cursorDatum, topSuggestionDatum;
- cursorDatum = this.dropdown.getDatumForCursor();
- topSuggestionDatum = this.dropdown.getDatumForTopSuggestion();
- if (cursorDatum) {
- this._select(cursorDatum);
- $e.preventDefault();
- } else if (this.autoselect && topSuggestionDatum) {
- this._select(topSuggestionDatum);
- $e.preventDefault();
+ var $selectable;
+ if ($selectable = this.menu.getActiveSelectable()) {
+ if (this.select($selectable)) {
+ $e.preventDefault();
+ $e.stopPropagation();
+ }
+ } else if (this.autoselect) {
+ if (this.select(this.menu.getTopSelectable())) {
+ $e.preventDefault();
+ $e.stopPropagation();
+ }
}
},
_onTabKeyed: function onTabKeyed(type, $e) {
- var datum;
- if (datum = this.dropdown.getDatumForCursor()) {
- this._select(datum);
- $e.preventDefault();
- } else {
- this._autocomplete(true);
+ var $selectable;
+ if ($selectable = this.menu.getActiveSelectable()) {
+ this.select($selectable) && $e.preventDefault();
+ } else if (this.autoselect) {
+ if ($selectable = this.menu.getTopSelectable()) {
+ this.autocomplete($selectable) && $e.preventDefault();
+ }
}
},
_onEscKeyed: function onEscKeyed() {
- this.dropdown.close();
- this.input.resetInputValue();
+ this.close();
},
_onUpKeyed: function onUpKeyed() {
- var query = this.input.getQuery();
- this.dropdown.isEmpty && query.length >= this.minLength ? this.dropdown.update(query) : this.dropdown.moveCursorUp();
- this.dropdown.open();
+ this.moveCursor(-1);
},
_onDownKeyed: function onDownKeyed() {
- var query = this.input.getQuery();
- this.dropdown.isEmpty && query.length >= this.minLength ? this.dropdown.update(query) : this.dropdown.moveCursorDown();
- this.dropdown.open();
+ this.moveCursor(+1);
},
_onLeftKeyed: function onLeftKeyed() {
- this.dir === "rtl" && this._autocomplete();
+ if (this.dir === "rtl" && this.input.isCursorAtEnd()) {
+ this.autocomplete(this.menu.getActiveSelectable() || this.menu.getTopSelectable());
+ }
},
_onRightKeyed: function onRightKeyed() {
- this.dir === "ltr" && this._autocomplete();
+ if (this.dir === "ltr" && this.input.isCursorAtEnd()) {
+ this.autocomplete(this.menu.getActiveSelectable() || this.menu.getTopSelectable());
+ }
},
_onQueryChanged: function onQueryChanged(e, query) {
- this.input.clearHintIfInvalid();
- query.length >= this.minLength ? this.dropdown.update(query) : this.dropdown.empty();
- this.dropdown.open();
- this._setLanguageDirection();
+ this._minLengthMet(query) ? this.menu.update(query) : this.menu.empty();
},
_onWhitespaceChanged: function onWhitespaceChanged() {
this._updateHint();
- this.dropdown.open();
},
- _setLanguageDirection: function setLanguageDirection() {
- var dir;
- if (this.dir !== (dir = this.input.getLanguageDirection())) {
+ _onLangDirChanged: function onLangDirChanged(e, dir) {
+ if (this.dir !== dir) {
this.dir = dir;
- this.$node.css("direction", dir);
- this.dropdown.setLanguageDirection(dir);
+ this.menu.setLanguageDirection(dir);
}
},
+ _openIfActive: function openIfActive() {
+ this.isActive() && this.open();
+ },
+ _minLengthMet: function minLengthMet(query) {
+ query = _.isString(query) ? query : this.input.getQuery() || "";
+ return query.length >= this.minLength;
+ },
_updateHint: function updateHint() {
- var datum, val, query, escapedQuery, frontMatchRegEx, match;
- datum = this.dropdown.getDatumForTopSuggestion();
- if (datum && this.dropdown.isVisible() && !this.input.hasOverflow()) {
- val = this.input.getInputValue();
+ var $selectable, data, val, query, escapedQuery, frontMatchRegEx, match;
+ $selectable = this.menu.getTopSelectable();
+ data = this.menu.getSelectableData($selectable);
+ val = this.input.getInputValue();
+ if (data && !_.isBlankString(val) && !this.input.hasOverflow()) {
query = Input.normalizeQuery(val);
escapedQuery = _.escapeRegExChars(query);
frontMatchRegEx = new RegExp("^(?:" + escapedQuery + ")(.+$)", "i");
- match = frontMatchRegEx.exec(datum.value);
- match ? this.input.setHint(val + match[1]) : this.input.clearHint();
+ match = frontMatchRegEx.exec(data.val);
+ match && this.input.setHint(val + match[1]);
} else {
this.input.clearHint();
}
},
- _autocomplete: function autocomplete(laxCursor) {
- var hint, query, isCursorAtEnd, datum;
- hint = this.input.getHint();
- query = this.input.getQuery();
- isCursorAtEnd = laxCursor || this.input.isCursorAtEnd();
- if (hint && query !== hint && isCursorAtEnd) {
- datum = this.dropdown.getDatumForTopSuggestion();
- datum && this.input.setInputValue(datum.value);
- this.eventBus.trigger("autocompleted", datum.raw, datum.datasetName);
+ isEnabled: function isEnabled() {
+ return this.enabled;
+ },
+ enable: function enable() {
+ this.enabled = true;
+ },
+ disable: function disable() {
+ this.enabled = false;
+ },
+ isActive: function isActive() {
+ return this.active;
+ },
+ activate: function activate() {
+ if (this.isActive()) {
+ return true;
+ } else if (!this.isEnabled() || this.eventBus.before("active")) {
+ return false;
+ } else {
+ this.active = true;
+ this.eventBus.trigger("active");
+ return true;
}
},
- _select: function select(datum) {
- this.input.setQuery(datum.value);
- this.input.setInputValue(datum.value, true);
- this._setLanguageDirection();
- this.eventBus.trigger("selected", datum.raw, datum.datasetName);
- this.dropdown.close();
- _.defer(_.bind(this.dropdown.empty, this.dropdown));
+ deactivate: function deactivate() {
+ if (!this.isActive()) {
+ return true;
+ } else if (this.eventBus.before("idle")) {
+ return false;
+ } else {
+ this.active = false;
+ this.close();
+ this.eventBus.trigger("idle");
+ return true;
+ }
+ },
+ isOpen: function isOpen() {
+ return this.menu.isOpen();
},
open: function open() {
- this.dropdown.open();
+ if (!this.isOpen() && !this.eventBus.before("open")) {
+ this.input.setAriaExpanded(true);
+ this.menu.open();
+ this._updateHint();
+ this.eventBus.trigger("open");
+ }
+ return this.isOpen();
},
close: function close() {
- this.dropdown.close();
+ if (this.isOpen() && !this.eventBus.before("close")) {
+ this.input.setAriaExpanded(false);
+ this.menu.close();
+ this.input.clearHint();
+ this.input.resetInputValue();
+ this.eventBus.trigger("close");
+ }
+ return !this.isOpen();
},
setVal: function setVal(val) {
- val = _.toStr(val);
- if (this.isActivated) {
- this.input.setInputValue(val);
- } else {
- this.input.setQuery(val);
- this.input.setInputValue(val, true);
- }
- this._setLanguageDirection();
+ this.input.setQuery(_.toStr(val));
},
getVal: function getVal() {
return this.input.getQuery();
},
+ select: function select($selectable) {
+ var data = this.menu.getSelectableData($selectable);
+ if (data && !this.eventBus.before("select", data.obj, data.dataset)) {
+ this.input.setQuery(data.val, true);
+ this.eventBus.trigger("select", data.obj, data.dataset);
+ this.close();
+ return true;
+ }
+ return false;
+ },
+ autocomplete: function autocomplete($selectable) {
+ var query, data, isValid;
+ query = this.input.getQuery();
+ data = this.menu.getSelectableData($selectable);
+ isValid = data && query !== data.val;
+ if (isValid && !this.eventBus.before("autocomplete", data.obj, data.dataset)) {
+ this.input.setQuery(data.val);
+ this.eventBus.trigger("autocomplete", data.obj, data.dataset);
+ return true;
+ }
+ return false;
+ },
+ moveCursor: function moveCursor(delta) {
+ var query, $candidate, data, suggestion, datasetName, cancelMove, id;
+ query = this.input.getQuery();
+ $candidate = this.menu.selectableRelativeToCursor(delta);
+ data = this.menu.getSelectableData($candidate);
+ suggestion = data ? data.obj : null;
+ datasetName = data ? data.dataset : null;
+ id = $candidate ? $candidate.attr("id") : null;
+ this.input.trigger("cursorchange", id);
+ cancelMove = this._minLengthMet() && this.menu.update(query);
+ if (!cancelMove && !this.eventBus.before("cursorchange", suggestion, datasetName)) {
+ this.menu.setCursor($candidate);
+ if (data) {
+ if (typeof data.val === "string") {
+ this.input.setInputValue(data.val);
+ }
+ } else {
+ this.input.resetInputValue();
+ this._updateHint();
+ }
+ this.eventBus.trigger("cursorchange", suggestion, datasetName);
+ return true;
+ }
+ return false;
+ },
destroy: function destroy() {
this.input.destroy();
- this.dropdown.destroy();
- destroyDomStructure(this.$node);
- this.$node = null;
+ this.menu.destroy();
}
});
return Typeahead;
- function buildDom(input, withHint) {
- var $input, $wrapper, $dropdown, $hint;
- $input = $(input);
- $wrapper = $(html.wrapper).css(css.wrapper);
- $dropdown = $(html.dropdown).css(css.dropdown);
- $hint = $input.clone().css(css.hint).css(getBackgroundStyles($input));
- $hint.val("").removeData().addClass("tt-hint").removeAttr("id name placeholder required").prop("readonly", true).attr({
- autocomplete: "off",
+ function c(ctx) {
+ var methods = [].slice.call(arguments, 1);
+ return function() {
+ var args = [].slice.call(arguments);
+ _.each(methods, function(method) {
+ return ctx[method].apply(ctx, args);
+ });
+ };
+ }
+ }();
+ (function() {
+ "use strict";
+ var old, keys, methods;
+ old = $.fn.typeahead;
+ keys = {
+ www: "tt-www",
+ attrs: "tt-attrs",
+ typeahead: "tt-typeahead"
+ };
+ methods = {
+ initialize: function initialize(o, datasets) {
+ var www;
+ datasets = _.isArray(datasets) ? datasets : [].slice.call(arguments, 1);
+ o = o || {};
+ www = WWW(o.classNames);
+ return this.each(attach);
+ function attach() {
+ var $input, $wrapper, $hint, $menu, defaultHint, defaultMenu, eventBus, input, menu, status, typeahead, MenuConstructor;
+ _.each(datasets, function(d) {
+ d.highlight = !!o.highlight;
+ });
+ $input = $(this);
+ $wrapper = $(www.html.wrapper);
+ $hint = $elOrNull(o.hint);
+ $menu = $elOrNull(o.menu);
+ defaultHint = o.hint !== false && !$hint;
+ defaultMenu = o.menu !== false && !$menu;
+ defaultHint && ($hint = buildHintFromInput($input, www));
+ defaultMenu && ($menu = $(www.html.menu).css(www.css.menu));
+ $hint && $hint.val("");
+ $input = prepInput($input, www);
+ if (defaultHint || defaultMenu) {
+ $wrapper.css(www.css.wrapper);
+ $input.css(defaultHint ? www.css.input : www.css.inputWithNoHint);
+ $input.wrap($wrapper).parent().prepend(defaultHint ? $hint : null).append(defaultMenu ? $menu : null);
+ }
+ MenuConstructor = defaultMenu ? DefaultMenu : Menu;
+ eventBus = new EventBus({
+ el: $input
+ });
+ input = new Input({
+ hint: $hint,
+ input: $input,
+ menu: $menu
+ }, www);
+ menu = new MenuConstructor({
+ node: $menu,
+ datasets: datasets
+ }, www);
+ status = new Status({
+ $input: $input,
+ menu: menu
+ });
+ typeahead = new Typeahead({
+ input: input,
+ menu: menu,
+ eventBus: eventBus,
+ minLength: o.minLength,
+ autoselect: o.autoselect
+ }, www);
+ $input.data(keys.www, www);
+ $input.data(keys.typeahead, typeahead);
+ }
+ },
+ isEnabled: function isEnabled() {
+ var enabled;
+ ttEach(this.first(), function(t) {
+ enabled = t.isEnabled();
+ });
+ return enabled;
+ },
+ enable: function enable() {
+ ttEach(this, function(t) {
+ t.enable();
+ });
+ return this;
+ },
+ disable: function disable() {
+ ttEach(this, function(t) {
+ t.disable();
+ });
+ return this;
+ },
+ isActive: function isActive() {
+ var active;
+ ttEach(this.first(), function(t) {
+ active = t.isActive();
+ });
+ return active;
+ },
+ activate: function activate() {
+ ttEach(this, function(t) {
+ t.activate();
+ });
+ return this;
+ },
+ deactivate: function deactivate() {
+ ttEach(this, function(t) {
+ t.deactivate();
+ });
+ return this;
+ },
+ isOpen: function isOpen() {
+ var open;
+ ttEach(this.first(), function(t) {
+ open = t.isOpen();
+ });
+ return open;
+ },
+ open: function open() {
+ ttEach(this, function(t) {
+ t.open();
+ });
+ return this;
+ },
+ close: function close() {
+ ttEach(this, function(t) {
+ t.close();
+ });
+ return this;
+ },
+ select: function select(el) {
+ var success = false, $el = $(el);
+ ttEach(this.first(), function(t) {
+ success = t.select($el);
+ });
+ return success;
+ },
+ autocomplete: function autocomplete(el) {
+ var success = false, $el = $(el);
+ ttEach(this.first(), function(t) {
+ success = t.autocomplete($el);
+ });
+ return success;
+ },
+ moveCursor: function moveCursoe(delta) {
+ var success = false;
+ ttEach(this.first(), function(t) {
+ success = t.moveCursor(delta);
+ });
+ return success;
+ },
+ val: function val(newVal) {
+ var query;
+ if (!arguments.length) {
+ ttEach(this.first(), function(t) {
+ query = t.getVal();
+ });
+ return query;
+ } else {
+ ttEach(this, function(t) {
+ t.setVal(_.toStr(newVal));
+ });
+ return this;
+ }
+ },
+ destroy: function destroy() {
+ ttEach(this, function(typeahead, $input) {
+ revert($input);
+ typeahead.destroy();
+ });
+ return this;
+ }
+ };
+ $.fn.typeahead = function(method) {
+ if (methods[method]) {
+ return methods[method].apply(this, [].slice.call(arguments, 1));
+ } else {
+ return methods.initialize.apply(this, arguments);
+ }
+ };
+ $.fn.typeahead.noConflict = function noConflict() {
+ $.fn.typeahead = old;
+ return this;
+ };
+ function ttEach($els, fn) {
+ $els.each(function() {
+ var $input = $(this), typeahead;
+ (typeahead = $input.data(keys.typeahead)) && fn(typeahead, $input);
+ });
+ }
+ function buildHintFromInput($input, www) {
+ return $input.clone().addClass(www.classes.hint).removeData().css(www.css.hint).css(getBackgroundStyles($input)).prop({
+ readonly: true,
+ required: false
+ }).removeAttr("id name placeholder").removeClass("required").attr({
spellcheck: "false",
tabindex: -1
});
- $input.data(attrsKey, {
+ }
+ function prepInput($input, www) {
+ $input.data(keys.attrs, {
dir: $input.attr("dir"),
autocomplete: $input.attr("autocomplete"),
spellcheck: $input.attr("spellcheck"),
style: $input.attr("style")
});
- $input.addClass("tt-input").attr({
- autocomplete: "off",
+ $input.addClass(www.classes.input).attr({
spellcheck: false
- }).css(withHint ? css.input : css.inputWithNoHint);
+ });
try {
!$input.attr("dir") && $input.attr("dir", "auto");
} catch (e) {}
- return $input.wrap($wrapper).parent().prepend(withHint ? $hint : null).append($dropdown);
+ return $input;
}
function getBackgroundStyles($el) {
return {
@@ -1681,102 +2618,24 @@
backgroundSize: $el.css("background-size")
};
}
- function destroyDomStructure($node) {
- var $input = $node.find(".tt-input");
- _.each($input.data(attrsKey), function(val, key) {
+ function revert($input) {
+ var www, $wrapper;
+ www = $input.data(keys.www);
+ $wrapper = $input.parent().filter(www.selectors.wrapper);
+ _.each($input.data(keys.attrs), function(val, key) {
_.isUndefined(val) ? $input.removeAttr(key) : $input.attr(key, val);
});
- $input.detach().removeData(attrsKey).removeClass("tt-input").insertAfter($node);
- $node.remove();
+ $input.removeData(keys.typeahead).removeData(keys.www).removeData(keys.attr).removeClass(www.classes.input);
+ if ($wrapper.length) {
+ $input.detach().insertAfter($wrapper);
+ $wrapper.remove();
+ }
+ }
+ function $elOrNull(obj) {
+ var isValid, $el;
+ isValid = _.isJQuery(obj) || _.isElement(obj);
+ $el = isValid ? $(obj).first() : [];
+ return $el.length ? $el : null;
}
- }();
- (function() {
- "use strict";
- var old, typeaheadKey, methods;
- old = $.fn.typeahead;
- typeaheadKey = "ttTypeahead";
- methods = {
- initialize: function initialize(o, datasets) {
- datasets = _.isArray(datasets) ? datasets : [].slice.call(arguments, 1);
- o = o || {};
- return this.each(attach);
- function attach() {
- var $input = $(this), eventBus, typeahead;
- _.each(datasets, function(d) {
- d.highlight = !!o.highlight;
- });
- typeahead = new Typeahead({
- input: $input,
- eventBus: eventBus = new EventBus({
- el: $input
- }),
- withHint: _.isUndefined(o.hint) ? true : !!o.hint,
- minLength: o.minLength,
- autoselect: o.autoselect,
- datasets: datasets
- });
- $input.data(typeaheadKey, typeahead);
- }
- },
- open: function open() {
- return this.each(openTypeahead);
- function openTypeahead() {
- var $input = $(this), typeahead;
- if (typeahead = $input.data(typeaheadKey)) {
- typeahead.open();
- }
- }
- },
- close: function close() {
- return this.each(closeTypeahead);
- function closeTypeahead() {
- var $input = $(this), typeahead;
- if (typeahead = $input.data(typeaheadKey)) {
- typeahead.close();
- }
- }
- },
- val: function val(newVal) {
- return !arguments.length ? getVal(this.first()) : this.each(setVal);
- function setVal() {
- var $input = $(this), typeahead;
- if (typeahead = $input.data(typeaheadKey)) {
- typeahead.setVal(newVal);
- }
- }
- function getVal($input) {
- var typeahead, query;
- if (typeahead = $input.data(typeaheadKey)) {
- query = typeahead.getVal();
- }
- return query;
- }
- },
- destroy: function destroy() {
- return this.each(unattach);
- function unattach() {
- var $input = $(this), typeahead;
- if (typeahead = $input.data(typeaheadKey)) {
- typeahead.destroy();
- $input.removeData(typeaheadKey);
- }
- }
- }
- };
- $.fn.typeahead = function(method) {
- var tts;
- if (methods[method] && method !== "initialize") {
- tts = this.filter(function() {
- return !!$(this).data(typeaheadKey);
- });
- return methods[method].apply(tts, [].slice.call(arguments, 1));
- } else {
- return methods.initialize.apply(this, arguments);
- }
- };
- $.fn.typeahead.noConflict = function noConflict() {
- $.fn.typeahead = old;
- return this;
- };
})();
-})(window.jQuery);
\ No newline at end of file
+});
diff --git a/cps/static/js/main.js b/cps/static/js/main.js
index 988e3b9f..48c66767 100644
--- a/cps/static/js/main.js
+++ b/cps/static/js/main.js
@@ -15,7 +15,6 @@
* along with this program. If not, see
.
*/
-
function getPath() {
var jsFileLocation = $("script[src*=jquery]").attr("src"); // the js file path
return jsFileLocation.substr(0, jsFileLocation.search("/static/js/libs/jquery.min.js")); // the js folder path
@@ -113,6 +112,14 @@ $("#btn-upload").change(function() {
$("#form-upload").submit();
});
+$("#form-upload").uploadprogress({
+ redirect_url: getPath() + "/", //"{{ url_for('web.index')}}",
+ uploadedMsg: $("#form-upload").data("message"), //"{{_('Upload done, processing, please wait...')}}",
+ modalTitle: $("#form-upload").data("title"), //"{{_('Uploading...')}}",
+ modalFooter: $("#form-upload").data("footer"), //"{{_('Close')}}",
+ modalTitleFailed: $("#form-upload").data("failed") //"{{_('Error')}}"
+});
+
$(document).ready(function() {
var inp = $('#query').first()
if (inp.length) {
@@ -224,6 +231,16 @@ $(function() {
var preFilters = $.Callbacks();
$.ajaxPrefilter(preFilters.fire);
+ // equip all post requests with csrf_token
+ var csrftoken = $("input[name='csrf_token']").val();
+ $.ajaxSetup({
+ beforeSend: function(xhr, settings) {
+ if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) {
+ xhr.setRequestHeader("X-CSRFToken", csrftoken)
+ }
+ }
+ });
+
function restartTimer() {
$("#spinner").addClass("hidden");
$("#RestartDialog").modal("hide");
@@ -246,7 +263,7 @@ $(function() {
function updateTimer() {
$.ajax({
dataType: "json",
- url: window.location.pathname + "/../../get_updater_status",
+ url: getPath() + "/get_updater_status",
success: function success(data) {
$("#DialogContent").html(updateText[data.status]);
if (data.status > 6) {
@@ -445,8 +462,8 @@ $(function() {
$.ajax({
type: "POST",
dataType: "json",
- data: { start: "True"},
- url: window.location.pathname + "/../../get_updater_status",
+ data: { start: "True" },
+ url: getPath() + "/get_updater_status",
success: function success(data) {
updateText = data.text;
$("#DialogContent").html(updateText[data.status]);
@@ -577,7 +594,7 @@ $(function() {
method:"post",
dataType: "json",
url: window.location.pathname + "/../../ajax/simulatedbchange",
- data: {config_calibre_dir: $("#config_calibre_dir").val()},
+ data: {config_calibre_dir: $("#config_calibre_dir").val(), csrf_token: $("input[name='csrf_token']").val()},
success: function success(data) {
if ( data.change ) {
if ( data.valid ) {
@@ -650,10 +667,10 @@ $(function() {
var folder = target.data("folderonly");
var filter = target.data("filefilter");
$("#element_selected").text(path);
- $("#file_confirm")[0].attributes["data-link"].value = target.data("link");
- $("#file_confirm")[0].attributes["data-folderonly"].value = (typeof folder === 'undefined') ? false : true;
- $("#file_confirm")[0].attributes["data-filefilter"].value = (typeof filter === 'undefined') ? "" : filter;
- $("#file_confirm")[0].attributes["data-newfile"].value = target.data("newfile");
+ $("#file_confirm").data("link", target.data("link"));
+ $("#file_confirm").data("folderonly", (typeof folder === 'undefined') ? false : true);
+ $("#file_confirm").data("filefilter", (typeof filter === 'undefined') ? "" : filter);
+ $("#file_confirm").data("newfile", target.data("newfile"));
fillFileTable(path,"dir", folder, filter);
});
@@ -667,7 +684,7 @@ $(function() {
var folder = $(file_confirm).data("folderonly");
var filter = $(file_confirm).data("filefilter");
var newfile = $(file_confirm).data("newfile");
- if (newfile !== 'undefined') {
+ if (newfile !== "") {
$("#element_selected").text(path + $("#new_file".text()));
} else {
$("#element_selected").text(path);
@@ -713,7 +730,7 @@ $(function() {
method:"post",
contentType: "application/json; charset=utf-8",
dataType: "json",
- url: window.location.pathname + "/../ajax/view",
+ url: getPath() + "/ajax/view",
data: "{\"series\": {\"series_view\": \""+ view +"\"}}",
success: function success() {
location.reload();
diff --git a/cps/static/js/reading/djvu_reader.js b/cps/static/js/reading/djvu_reader.js
new file mode 100644
index 00000000..c93d705a
--- /dev/null
+++ b/cps/static/js/reading/djvu_reader.js
@@ -0,0 +1,21 @@
+/* This file is part of the Calibre-Web (https://github.com/janeczku/calibre-web)
+ * Copyright (C) 2021 Ozzieisaacs
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see
.
+ */
+
+var DJVU_CONTEXT = {
+ background: "#666",
+ uiHideDelay: 1500,
+};
diff --git a/cps/static/js/reading/txt_reader.js b/cps/static/js/reading/txt_reader.js
new file mode 100644
index 00000000..9cfb51f5
--- /dev/null
+++ b/cps/static/js/reading/txt_reader.js
@@ -0,0 +1,86 @@
+/* This file is part of the Calibre-Web (https://github.com/janeczku/calibre-web)
+ * Copyright (C) 2021 Ozzieisaacs
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see
.
+ */
+
+$(document).ready(function() {
+ //to int
+ $("#area").width($("#area").width());
+ $("#content").width($("#content").width());
+ //bind text
+ $("#content").load($("#readmain").data('load'), function(textStr) {
+ $(this).height($(this).parent().height()*0.95);
+ $(this).text(textStr);
+ });
+ //keybind
+ $(document).keydown(function(event){
+ if(event.keyCode == 37){
+ prevPage();
+ }
+ if(event.keyCode == 39){
+ nextPage();
+ }
+ });
+ //click
+ $( "#left" ).click(function() {
+ prevPage();
+ });
+ $( "#right" ).click(function() {
+ nextPage();
+ });
+ $("#readmain").swipe( {
+ swipeRight:function() {
+ prevPage();
+ },
+ swipeLeft:function() {
+ nextPage();
+ },
+ });
+
+ //bind mouse
+ $(window).bind('DOMMouseScroll mousewheel', function(event) {
+ var delta = 0;
+ if (event.originalEvent.wheelDelta) {
+ delta = event.originalEvent.wheelDelta;
+ } else if (event.originalEvent.detail) {
+ delta = event.originalEvent.detail*-1;
+ }
+ if (delta >= 0) {
+ prevPage();
+ } else {
+ nextPage();
+ }
+ });
+
+ //page animate
+ var origwidth = $("#content")[0].getBoundingClientRect().width;
+ var gap = 20;
+ function prevPage() {
+ if($("#content").offset().left > 0) {
+ return;
+ }
+ leftoff = $("#content").offset().left;
+ leftoff = leftoff+origwidth+gap;
+ $("#content").offset({left:leftoff});
+ }
+ function nextPage() {
+ leftoff = $("#content").offset().left;
+ leftoff = leftoff-origwidth-gap;
+ if (leftoff + $("#content")[0].scrollWidth < 0) {
+ return;
+ }
+ $("#content").offset({left:leftoff});
+ }
+});
diff --git a/cps/static/js/remote_login.js b/cps/static/js/remote_login.js
new file mode 100644
index 00000000..f0d364dc
--- /dev/null
+++ b/cps/static/js/remote_login.js
@@ -0,0 +1,36 @@
+/* This file is part of the Calibre-Web (https://github.com/janeczku/calibre-web)
+ * Copyright (C) 2017-2021 jkrehm, OzzieIsaacs
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see
.
+ */
+
+(function () {
+ // Poll the server to check if the user has authenticated
+ var t = setInterval(function () {
+ $.post(getPath() + "/ajax/verify_token", { token: $("#verify_url").data("token") })
+ .done(function(response) {
+ if (response.status === 'success') {
+ // Wait a tick so cookies are updated
+ setTimeout(function () {
+ window.location.href = getPath() + '/';
+ }, 0);
+ }
+ })
+ .fail(function (xhr) {
+ clearInterval(t);
+ var response = JSON.parse(xhr.responseText);
+ alert(response.message);
+ });
+ }, 5000);
+})()
diff --git a/cps/static/js/shelforder.js b/cps/static/js/shelforder.js
index 62b7e9f3..5cbe7109 100644
--- a/cps/static/js/shelforder.js
+++ b/cps/static/js/shelforder.js
@@ -35,6 +35,7 @@ function sendData(path) {
var form = document.createElement("form");
form.setAttribute("method", "post");
form.setAttribute("action", path);
+ // form.setAttribute("csrf_token", );
for (counter = 0;counter < maxElements;counter++) {
tmp[counter] = elements[counter].getAttribute("id");
@@ -44,6 +45,10 @@ function sendData(path) {
hiddenField.setAttribute("value", String(counter + 1));
form.appendChild(hiddenField);
}
+ $("
")
+ .attr("name", "csrf_token").val($("input[name='csrf_token']").val())
+ .appendTo(form);
+
document.body.appendChild(form);
form.submit();
}
diff --git a/cps/subproc_wrapper.py b/cps/subproc_wrapper.py
index 3cc4a070..187b2cb2 100644
--- a/cps/subproc_wrapper.py
+++ b/cps/subproc_wrapper.py
@@ -16,7 +16,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see
.
-from __future__ import division, print_function, unicode_literals
import sys
import os
import subprocess
@@ -33,13 +32,8 @@ def process_open(command, quotes=(), env=None, sout=subprocess.PIPE, serr=subpro
if key in quotes:
command[key] = '"' + element + '"'
exc_command = " ".join(command)
- if sys.version_info < (3, 0):
- exc_command = exc_command.encode(sys.getfilesystemencoding())
else:
- if sys.version_info < (3, 0):
- exc_command = [x.encode(sys.getfilesystemencoding()) for x in command]
- else:
- exc_command = [x for x in command]
+ exc_command = [x for x in command]
return subprocess.Popen(exc_command, shell=False, stdout=sout, stderr=serr, universal_newlines=newlines, env=env) # nosec
diff --git a/cps/tasks/convert.py b/cps/tasks/convert.py
index 56cc7076..08fb1644 100644
--- a/cps/tasks/convert.py
+++ b/cps/tasks/convert.py
@@ -1,4 +1,21 @@
-from __future__ import division, print_function, unicode_literals
+# -*- coding: utf-8 -*-
+
+# This file is part of the Calibre-Web (https://github.com/janeczku/calibre-web)
+# Copyright (C) 2020 pwr
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see
.
+
import sys
import os
import re
@@ -161,8 +178,6 @@ class TaskConvert(CalibreTask):
while True:
nextline = p.stdout.readlines()
nextline = [x.strip('\n') for x in nextline if x != '\n']
- if sys.version_info < (3, 0):
- nextline = [x.decode('utf-8') for x in nextline]
for line in nextline:
log.debug(line)
if p.poll() is not None:
@@ -207,10 +222,6 @@ class TaskConvert(CalibreTask):
while p.poll() is None:
nextline = p.stdout.readline()
- if os.name == 'nt' and sys.version_info < (3, 0):
- nextline = nextline.decode('windows-1252')
- elif os.name == 'posix' and sys.version_info < (3, 0):
- nextline = nextline.decode('utf-8')
log.debug(nextline.strip('\r\n'))
# parse progress string from calibre-converter
progress = re.search(r"(\d+)%\s.*", nextline)
@@ -224,8 +235,6 @@ class TaskConvert(CalibreTask):
calibre_traceback = p.stderr.readlines()
error_message = ""
for ele in calibre_traceback:
- if sys.version_info < (3, 0):
- ele = ele.decode('utf-8')
log.debug(ele.strip('\n'))
if not ele.startswith('Traceback') and not ele.startswith(' File'):
error_message = _("Calibre failed with error: %(error)s", error=ele.strip('\n'))
diff --git a/cps/tasks/mail.py b/cps/tasks/mail.py
index 292114d5..2e95ee98 100644
--- a/cps/tasks/mail.py
+++ b/cps/tasks/mail.py
@@ -1,11 +1,27 @@
-from __future__ import division, print_function, unicode_literals
+# -*- coding: utf-8 -*-
+
+# This file is part of the Calibre-Web (https://github.com/janeczku/calibre-web)
+# Copyright (C) 2020 pwr
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see
.
+
import sys
import os
import smtplib
import threading
import socket
import mimetypes
-import base64
try:
from StringIO import StringIO
@@ -162,17 +178,11 @@ class TaskEmail(CalibreTask):
log.debug_or_exception(ex)
self._handleError(u'Error sending e-mail: {}'.format(ex))
-
def send_standard_email(self, msg):
use_ssl = int(self.settings.get('mail_use_ssl', 0))
timeout = 600 # set timeout to 5mins
- # redirect output to logfile on python2 on python3 debugoutput is caught with overwritten
- # _print_debug function
- if sys.version_info < (3, 0):
- org_smtpstderr = smtplib.stderr
- smtplib.stderr = logger.StderrLogger('worker.smtp')
-
+ # on python3 debugoutput is caught with overwritten _print_debug function
log.debug("Start sending e-mail")
if use_ssl == 2:
self.asyncSMTP = EmailSSL(self.settings["mail_server"], self.settings["mail_port"],
@@ -198,9 +208,6 @@ class TaskEmail(CalibreTask):
self._handleSuccess()
log.debug("E-mail send successfully")
- if sys.version_info < (3, 0):
- smtplib.stderr = org_smtpstderr
-
def send_gmail_email(self, message):
return gmail.send_messsage(self.settings.get('mail_gmail_token', None), message)
@@ -218,7 +225,6 @@ class TaskEmail(CalibreTask):
self.asyncSMTP = None
self._progress = x
-
@classmethod
def _get_attachment(cls, bookpath, filename):
"""Get file as MIMEBase message"""
diff --git a/cps/tasks/upload.py b/cps/tasks/upload.py
index d7ef34c2..6a341cdd 100644
--- a/cps/tasks/upload.py
+++ b/cps/tasks/upload.py
@@ -1,4 +1,20 @@
-from __future__ import division, print_function, unicode_literals
+# -*- coding: utf-8 -*-
+
+# This file is part of the Calibre-Web (https://github.com/janeczku/calibre-web)
+# Copyright (C) 2020 pwr
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see
.
from datetime import datetime
from cps.services.worker import CalibreTask, STAT_FINISH_SUCCESS
diff --git a/cps/templates/admin.html b/cps/templates/admin.html
index 81ef955b..9a941594 100644
--- a/cps/templates/admin.html
+++ b/cps/templates/admin.html
@@ -186,6 +186,7 @@
{% if feature_support['updater'] %}
+
{{update_error}}
{{_('Check for Update')}}
{{_('Perform Update')}}
diff --git a/cps/templates/author.html b/cps/templates/author.html
index b011bae8..d82b2ebd 100644
--- a/cps/templates/author.html
+++ b/cps/templates/author.html
@@ -36,8 +36,8 @@
-
-
+
+
{% if entry.id in read_book_ids %}{% endif %}
diff --git a/cps/templates/book_edit.html b/cps/templates/book_edit.html
index 78a5cdc1..21ae98e6 100644
--- a/cps/templates/book_edit.html
+++ b/cps/templates/book_edit.html
@@ -23,20 +23,21 @@
{% if source_formats|length > 0 and conversion_formats|length > 0 %}
{{_('Convert book format:')}}