[bug] fix data and background feedback

This commit is contained in:
Kuldeep M 2019-07-16 18:56:47 +01:00
parent b23b7b22a6
commit 0aa76fca39
3 changed files with 109 additions and 69 deletions

View File

@ -17,6 +17,21 @@ var background = (function() {
}
};
mod.image = {
file: function(name, data) {
helper.setObject({
object: state.get(),
path: "background.image.file.name",
newValue: name
});
helper.setObject({
object: state.get(),
path: "background.image.file.data",
newValue: data
});
}
};
var bind = {};
bind.feedback = {
@ -108,13 +123,15 @@ var background = (function() {
controlBackgroundImageFileFeedback.appendChild(para1);
controlBackgroundImageFileFeedback.appendChild(para2);
},
success: function(action) {
success: function(name, action) {
var controlBackgroundImageFileFeedback = helper.e(".control-background-image-file-feedback");
var para1 = helper.node("p:Success! Setting Background image.|class:muted small");
var para2 = helper.node("p:" + state.get().background.image.file.name);
var para2 = helper.node("p:" + name);
controlBackgroundImageFileFeedback.appendChild(para1);
controlBackgroundImageFileFeedback.appendChild(para2);
if (action) {
bind.feedback.animation.set("is-pop", action);
};
},
clear: function() {
var controlBackgroundImageFileFeedback = helper.e(".control-background-image-file-feedback");
@ -159,26 +176,19 @@ var background = (function() {
reader.onload = function(event) {
if (fileList.item(0).size <= 5000000) {
if (fileList.item(0).type.split("/")[0] == "image") {
helper.setObject({
object: state.get(),
path: "background.image.file.name",
newValue: fileList[0].name
});
helper.setObject({
object: state.get(),
path: "background.image.file.data",
newValue: event.target.result
});
data.save();;
mod.image.file(fileList[0].name, event.target.result);
data.save();
render.feedback.clear();
render.feedback.success(render.image);
render.feedback.success(fileList[0].name, render.image);
render.input.clear();
} else {
// not an image file
render.feedback.clear();
render.feedback.fail.filetype(fileList[0].name);
render.input.clear();
};
} else {
// file size too big
render.feedback.clear();
render.feedback.fail.size(fileList[0].name);
render.input.clear();

View File

@ -91,55 +91,83 @@ var data = (function() {
tempAchor.remove();
};
var render = {
feedback: function(type) {
_renderFeedback(type);
var bind = {};
bind.feedback = {
animation: {
set: function(animationClass, action) {
var controlDataImportFeedback = helper.e(".control-data-import-feedback");
helper.addClass(controlDataImportFeedback, animationClass);
var animationEndAction = function() {
if (action) {
action();
};
bind.feedback.animation.reset();
};
controlDataImportFeedback.addEventListener("animationend", animationEndAction, false);
},
reset: function() {
var controlDataImportFeedback = helper.e(".control-data-import-feedback");
helper.removeClass(controlDataImportFeedback, "is-shake");
helper.removeClass(controlDataImportFeedback, "is-pop");
controlDataImportFeedback.removeEventListener("animationend", bind.feedback.animation.reset, false);
}
}
};
var _renderFeedback = function(type, data) {
var render = {};
render.reload = function() {
location.reload();
};
render.input = {
clear: function() {
var input = helper.e(".control-data-import");
input.value = "";
}
};
render.feedback = {
empty: function() {
var controlDataImportFeedback = helper.e(".control-data-import-feedback");
var _setFeedbackAnimation = function(animationClass) {
helper.addClass(controlDataImportFeedback, animationClass);
controlDataImportFeedback.addEventListener("animationend", _resetFeedbackAnimation, false);
var para1 = helper.node("p:No JSON file selected.|class:muted small");
controlDataImportFeedback.appendChild(para1);
},
success: function(name, action) {
var controlDataImportFeedback = helper.e(".control-data-import-feedback");
var para1 = helper.node("p:Success! Restoring nightTab Bookmarks and Settings.|class:muted small");
var para2 = helper.node("p:" + name);
controlDataImportFeedback.appendChild(para1);
controlDataImportFeedback.appendChild(para2);
if (action) {
bind.feedback.animation.set("is-pop", action);
};
var _resetFeedbackAnimation = function() {
helper.removeClass(controlDataImportFeedback, "is-shake");
helper.removeClass(controlDataImportFeedback, "is-pop");
controlDataImportFeedback.removeEventListener("animationend", _resetFeedbackAnimation, false);
};
var clear = function() {
},
clear: function() {
var controlDataImportFeedback = helper.e(".control-data-import-feedback");
while (controlDataImportFeedback.lastChild) {
controlDataImportFeedback.removeChild(controlDataImportFeedback.lastChild);
};
};
var feedbackMessage = {
empty: "No file selected.",
success: "Success! Restoring nightTab Bookmarks and Settings.",
fail: {
notNightTabJson: "Not the right kind of JSON file. Make sure the selected file came from nightTab.",
notJson: "Not a JSON file. Make sure the selected file came from nightTab."
}
};
var action = {
empty: function() {
var para1 = helper.node("p:" + feedbackMessage.empty + "|class:muted small");
controlDataImportFeedback.appendChild(para1);
},
success: function() {
var para1 = helper.node("p:" + feedbackMessage.current + "|class:muted small");
var para2 = helper.node("p:" + state.get().background.image.file.name);
fail: {
notJson: function(name) {
var controlDataImportFeedback = helper.e(".control-data-import-feedback");
var para1 = helper.node("p:Not a JSON file. Make sure the selected file came from nightTab.|class:small muted");
var para2 = helper.node("p:" + name);
controlDataImportFeedback.appendChild(para1);
controlDataImportFeedback.appendChild(para2);
controlDataImportFeedback.addEventListener("animationend", function() {
restore(JSON.parse(data));
location.reload();
}, false);
_setFeedbackAnimation("is-pop");
bind.feedback.animation.set("is-shake");
},
notNightTabJson: function(name) {
var controlDataImportFeedback = helper.e(".control-data-import-feedback");
var para1 = helper.node("p:Not the right kind of JSON file. Make sure the selected file came from nightTab.|class:small muted");
var para2 = helper.node("p:" + name);
controlDataImportFeedback.appendChild(para1);
controlDataImportFeedback.appendChild(para2);
bind.feedback.animation.set("is-shake");
}
}
};
clear();
action[type]();
};
var importData = function() {
@ -161,21 +189,23 @@ var data = (function() {
if (helper.isJsonString(event.target.result)) {
// is this a nightTab JSON
if (JSON.parse(event.target.result).nighttab) {
_renderFeedback("success", event.target.result);
// console.log("is a JSON and a nightTab file");
// controlDataImportFeedback.addEventListener("animationend", function() {
// restore(JSON.parse(event.target.result));
// location.reload();
// }, false);
render.feedback.clear();
render.feedback.success(fileList[0].name, function() {
restore(JSON.parse(event.target.result));
render.reload();
});
render.input.clear();
} else {
_renderFeedback("fail");
// console.log("is a JSON file but not a nightTab file");
// _feedback(feedbackMessage.fail.notNightTabJson, "is-shake");
// not a nightTab JSON file
render.feedback.clear();
render.feedback.fail.notNightTabJson(fileList[0].name);
render.input.clear();
};
} else {
_renderFeedback("fail");
// console.log("not a JSON file");
// _feedback(feedbackMessage.fail.notJson, "is-shake");
// not a JSON file
render.feedback.clear();
render.feedback.fail.notJson(fileList[0].name);
render.input.clear();
};
};
// invoke the reader
@ -184,7 +214,7 @@ var data = (function() {
var init = function() {
restore(data.load());
render.feedback("empty");
render.feedback.empty();
};
return {

View File

@ -1,6 +1,6 @@
var version = (function() {
var current = "3.42.0";
var current = "3.43.0";
var compare = function(a, b) {
var pa = a.split(".");