Commit 2816991d authored by Vanessa's avatar Vanessa

about #261

parent 4ccace5f
...@@ -225,6 +225,7 @@ blogSubtitle1Label=Blog Subtitle: ...@@ -225,6 +225,7 @@ blogSubtitle1Label=Blog Subtitle:
blogHost1Label=Blog Host: blogHost1Label=Blog Host:
submmitCommentLabel=Commit Comment submmitCommentLabel=Commit Comment
saveLabel=Save saveLabel=Save
autoSaveLabel=Auto Save
tagLabel=Tag tagLabel=Tag
tagsLabel=Tags tagsLabel=Tags
importedLabel=Imported importedLabel=Imported
......
...@@ -225,6 +225,7 @@ blogSubtitle1Label=\u535a\u5ba2\u5b50\u6807\u9898\uff1a ...@@ -225,6 +225,7 @@ blogSubtitle1Label=\u535a\u5ba2\u5b50\u6807\u9898\uff1a
blogHost1Label=\u535a\u5ba2\u5730\u5740\uff1a blogHost1Label=\u535a\u5ba2\u5730\u5740\uff1a
submmitCommentLabel=\u63d0\u4ea4\u8bc4\u8bba submmitCommentLabel=\u63d0\u4ea4\u8bc4\u8bba
saveLabel=\u4fdd\u5b58 saveLabel=\u4fdd\u5b58
autoSaveLabel=\u81ea\u52a8\u4fdd\u5b58
tagLabel=\u6807\u7b7e tagLabel=\u6807\u7b7e
tagsLabel=\u6807\u7b7e tagsLabel=\u6807\u7b7e
importedLabel=\u5df2\u5bfc\u5165 importedLabel=\u5df2\u5bfc\u5165
......
...@@ -114,7 +114,8 @@ ...@@ -114,7 +114,8 @@
"navLabel": "${navLabel}", "navLabel": "${navLabel}",
"userLabel": "${userLabel}", "userLabel": "${userLabel}",
"changeRoleLabel": "${changeRoleLabel}", "changeRoleLabel": "${changeRoleLabel}",
"visitorUserLabel": "${visitorUserLabel}" "visitorUserLabel": "${visitorUserLabel}",
"autoSaveLabel": "${autoSaveLabel}"
}; };
admin.init(); admin.init();
......
...@@ -32,7 +32,7 @@ admin.article = { ...@@ -32,7 +32,7 @@ admin.article = {
// 自动保存草稿定时器 // 自动保存草稿定时器
autoSaveDraftTimer: "", autoSaveDraftTimer: "",
// 自动保存间隔 // 自动保存间隔
AUTOSAVETIME: 3000, AUTOSAVETIME: 1000 * 60,
/** /**
* @description 获取文章并把值塞入发布文章页面 * @description 获取文章并把值塞入发布文章页面
* @param {String} id 文章 id * @param {String} id 文章 id
...@@ -171,7 +171,7 @@ admin.article = { ...@@ -171,7 +171,7 @@ admin.article = {
data: JSON.stringify(requestJSONObject), data: JSON.stringify(requestJSONObject),
success: function(result, textStatus) { success: function(result, textStatus) {
if (isAuto) { if (isAuto) {
$("#tipMsg").text("TODO:"); $("#tipMsg").text(Label.autoSaveLabel);
admin.article.status.id = result.oId; admin.article.status.id = result.oId;
return; return;
} }
...@@ -246,7 +246,7 @@ admin.article = { ...@@ -246,7 +246,7 @@ admin.article = {
data: JSON.stringify(requestJSONObject), data: JSON.stringify(requestJSONObject),
success: function(result, textStatus) { success: function(result, textStatus) {
if (isAuto) { if (isAuto) {
$("#tipMsg").text("TODO:"); $("#tipMsg").text(Label.autoSaveLabel);
return; return;
} }
...@@ -450,7 +450,6 @@ admin.article = { ...@@ -450,7 +450,6 @@ admin.article = {
* @description 自动保存草稿件 * @description 自动保存草稿件
*/ */
_autoSaveToDraft: function() { _autoSaveToDraft: function() {
console.log("auto");
if ($("#title").val().replace(/\s/g, "") === "" || if ($("#title").val().replace(/\s/g, "") === "" ||
admin.editors.articleEditor.getContent().replace(/\s/g, "") === "" || admin.editors.articleEditor.getContent().replace(/\s/g, "") === "" ||
$("#tag").val().replace(/\s/g, "") === "") { $("#tag").val().replace(/\s/g, "") === "") {
...@@ -458,13 +457,15 @@ admin.article = { ...@@ -458,13 +457,15 @@ admin.article = {
} }
if (admin.article.status.id) { if (admin.article.status.id) {
if (admin.article.status.isArticle) { if (admin.article.status.isArticle) {
admin.article.unPublish(true);
admin.article.status.isArticle = false; admin.article.status.isArticle = false;
admin.article.setStatus();
admin.article.unPublish(true);
} else { } else {
admin.article.update(false, true); admin.article.update(false, true);
} }
} else { } else {
admin.article.add(false, true); admin.article.add(false, true);
admin.article.status.isArticle = false;
} }
}, },
/** /**
...@@ -508,7 +509,7 @@ admin.article = { ...@@ -508,7 +509,7 @@ admin.article = {
cache: false, cache: false,
success: function(result, textStatus) { success: function(result, textStatus) {
if (isAuto) { if (isAuto) {
$("#tipMsg").text("TODO:"); $("#tipMsg").text(Label.autoSaveLabel);
return; return;
} }
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
/** /**
* index for admin * @description index for admin
* *
* @author <a href="mailto:LLY219@gmail.com">Liyuan Li</a> * @author <a href="mailto:LLY219@gmail.com">Liyuan Li</a>
* @version 1.0.2.2, May 28, 2013 * @version 1.0.2.2, May 28, 2013
...@@ -30,8 +30,8 @@ var Admin = function() { ...@@ -30,8 +30,8 @@ var Admin = function() {
}; };
$.extend(Admin.prototype, { $.extend(Admin.prototype, {
/* /**
* 登出 * @description 登出
*/ */
logout: function() { logout: function() {
window.location.href = latkeConfig.servePath + "/logout?goto=" + latkeConfig.servePath; window.location.href = latkeConfig.servePath + "/logout?goto=" + latkeConfig.servePath;
...@@ -43,9 +43,9 @@ $.extend(Admin.prototype, { ...@@ -43,9 +43,9 @@ $.extend(Admin.prototype, {
$("#tipMsg").text(""); $("#tipMsg").text("");
$("#loadMsg").text(""); $("#loadMsg").text("");
}, },
/* /**
* 根据当前页数设置 hash * @description 根据当前页数设置 hash
* @currentPage {string} 当前页 * @param {Int} currentPage 当前页
*/ */
setHashByPage: function(currentPage) { setHashByPage: function(currentPage) {
var hash = window.location.hash, var hash = window.location.hash,
...@@ -57,15 +57,15 @@ $.extend(Admin.prototype, { ...@@ -57,15 +57,15 @@ $.extend(Admin.prototype, {
} }
window.location.hash = hashList.join("/"); window.location.hash = hashList.join("/");
}, },
/* /**
* 设置某个 tab 被选择 * @description 设置某个 tab 被选择
* @id tab id * @param {Stirng} id id tab id
*/ */
selectTab: function(id) { selectTab: function(id) {
window.location.hash = "#" + id; window.location.hash = "#" + id;
}, },
/* /**
* 根据当前 hash 解析出当前页数及 hash 数组。 * @description 根据当前 hash 解析出当前页数及 hash 数组。
*/ */
analyseHash: function() { analyseHash: function() {
var hash = window.location.hash; var hash = window.location.hash;
...@@ -83,8 +83,8 @@ $.extend(Admin.prototype, { ...@@ -83,8 +83,8 @@ $.extend(Admin.prototype, {
} }
return tags; return tags;
}, },
/* /**
* 根据当前 hash 设置当前 tab * @description 根据当前 hash 设置当前 tab
*/ */
setCurByHash: function() { setCurByHash: function() {
$("#tipMsg").text(""); $("#tipMsg").text("");
...@@ -100,6 +100,14 @@ $.extend(Admin.prototype, { ...@@ -100,6 +100,14 @@ $.extend(Admin.prototype, {
return; return;
} }
if (tab !== "article") {
admin.article.clearDraftTimer();
} else if (tab === "article") {
admin.article.autoSaveDraftTimer = setInterval(function() {
admin.article._autoSaveToDraft();
}, admin.article.AUTOSAVETIME);
}
// 离开编辑器时进行提示 // 离开编辑器时进行提示
try { try {
// 除更新、发布、取消发布文章,编辑器中无内容外,离开编辑器需进行提示。 // 除更新、发布、取消发布文章,编辑器中无内容外,离开编辑器需进行提示。
...@@ -191,8 +199,8 @@ $.extend(Admin.prototype, { ...@@ -191,8 +199,8 @@ $.extend(Admin.prototype, {
$("#loadMsg").text(""); $("#loadMsg").text("");
} }
}, },
/* /**
* 初始化整个后台 * @description 初始化整个后台
*/ */
init: function() { init: function() {
//window.onerror = Util.error; //window.onerror = Util.error;
...@@ -213,9 +221,9 @@ $.extend(Admin.prototype, { ...@@ -213,9 +221,9 @@ $.extend(Admin.prototype, {
}, 6000); }, 6000);
$("#loadMsg").text(""); $("#loadMsg").text("");
}, },
/* /**
* @description tools and article collapse * @description tools and article collapse
* @param {bom} it 触发事件对象 * @param {Bom} it 触发事件对象
*/ */
collapseNav: function(it) { collapseNav: function(it) {
var subNav = $(it).next(); var subNav = $(it).next();
...@@ -227,8 +235,8 @@ $.extend(Admin.prototype, { ...@@ -227,8 +235,8 @@ $.extend(Admin.prototype, {
} }
}); });
}, },
/* /**
* 后台及当前页面所需插件初始化完后,对权限进行控制及当前页面属于 tools 时,tools 选项需展开。 * @description 后台及当前页面所需插件初始化完后,对权限进行控制及当前页面属于 tools 时,tools 选项需展开。
*/ */
inited: function() { inited: function() {
// Removes functions with the current user role // Removes functions with the current user role
...@@ -867,7 +875,7 @@ $.extend(TablePaginate.prototype, { ...@@ -867,7 +875,7 @@ $.extend(TablePaginate.prototype, {
* *
* @author <a href="mailto:LLY219@gmail.com">Liyuan Li</a> * @author <a href="mailto:LLY219@gmail.com">Liyuan Li</a>
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a> * @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.3.2, May 28, 2013 * @version 1.0.3.3, Jun 4, 2013
*/ */
admin.article = { admin.article = {
// 当发文章,取消发布,更新文章时设置为 false。不需在离开编辑器时进行提示。 // 当发文章,取消发布,更新文章时设置为 false。不需在离开编辑器时进行提示。
...@@ -878,25 +886,31 @@ admin.article = { ...@@ -878,25 +886,31 @@ admin.article = {
articleHadBeenPublished: undefined articleHadBeenPublished: undefined
}, },
content: "", content: "",
/* // 自动保存草稿定时器
* 获取文章并把值塞入发布文章页面 autoSaveDraftTimer: "",
* @id 文章 id // 自动保存间隔
* @isArticle 文章或者草稿 AUTOSAVETIME: 1000 * 60,
/**
* @description 获取文章并把值塞入发布文章页面
* @param {String} id 文章 id
* @param {Boolean} isArticle 文章或者草稿
*/ */
get: function (id, isArticle) { get: function(id, isArticle) {
this.status.id = id; this.status.id = id;
this.status.isArticle = isArticle this.status.isArticle = isArticle;
admin.selectTab("article/article"); admin.selectTab("article/article");
}, },
/**
getAndSet: function () { * @description 获取文章内容
*/
getAndSet: function() {
$("#loadMsg").text(Label.loadingLabel); $("#loadMsg").text(Label.loadingLabel);
$("#tipMsg").text(""); $("#tipMsg").text("");
$.ajax({ $.ajax({
url: latkeConfig.servePath + "/console/article/" + admin.article.status.id, url: latkeConfig.servePath + "/console/article/" + admin.article.status.id,
type: "GET", type: "GET",
cache: false, cache: false,
success: function(result, textStatus){ success: function(result, textStatus) {
$("#tipMsg").text(result.msg); $("#tipMsg").text(result.msg);
if (!result.sc) { if (!result.sc) {
$("#loadMsg").text(""); $("#loadMsg").text("");
...@@ -929,7 +943,7 @@ admin.article = { ...@@ -929,7 +943,7 @@ admin.article = {
// signs // signs
var signs = result.article.signs; var signs = result.article.signs;
$(".signs button").each(function (i) { $(".signs button").each(function(i) {
if (parseInt(result.article.articleSignId) === parseInt(signs[i].oId)) { if (parseInt(result.article.articleSignId) === parseInt(signs[i].oId)) {
$("#articleSign" + signs[i].oId).addClass("selected"); $("#articleSign" + signs[i].oId).addClass("selected");
} else { } else {
...@@ -942,14 +956,13 @@ admin.article = { ...@@ -942,14 +956,13 @@ admin.article = {
} }
}); });
}, },
/**
/* * @description 删除文章
* 删除文章 * @param {String} id 文章 id
* @id 文章 id * @param {String} fromId 文章来自草稿夹(draft)/文件夹(article)
* @fromId 文章来自草稿夹(draft)/文件夹(article) * @param {String} title 文章标题
* @title 文章标题
*/ */
del: function (id, fromId, title) { del: function(id, fromId, title) {
var isDelete = confirm(Label.confirmRemoveLabel + Label.articleLabel + '"' + title + '"?'); var isDelete = confirm(Label.confirmRemoveLabel + Label.articleLabel + '"' + title + '"?');
if (isDelete) { if (isDelete) {
$("#loadMsg").text(Label.loadingLabel); $("#loadMsg").text(Label.loadingLabel);
...@@ -959,7 +972,7 @@ admin.article = { ...@@ -959,7 +972,7 @@ admin.article = {
url: latkeConfig.servePath + "/console/article/" + id, url: latkeConfig.servePath + "/console/article/" + id,
type: "DELETE", type: "DELETE",
cache: false, cache: false,
success: function(result, textStatus){ success: function(result, textStatus) {
$("#tipMsg").text(result.msg); $("#tipMsg").text(result.msg);
if (!result.sc) { if (!result.sc) {
$("#loadMsg").text(""); $("#loadMsg").text("");
...@@ -971,12 +984,12 @@ admin.article = { ...@@ -971,12 +984,12 @@ admin.article = {
}); });
} }
}, },
/**
/* * @@description 添加文章
* 添加文章 * @param {Boolean} articleIsPublished 文章是否发布过
* @articleIsPublished 文章是否发布过 * @param {Boolean} isAuto 是否为自动保存
*/ */
add: function (articleIsPublished) { add: function(articleIsPublished, isAuto) {
if (admin.article.validate()) { if (admin.article.validate()) {
var that = this; var that = this;
that._addDisabled(); that._addDisabled();
...@@ -984,7 +997,7 @@ admin.article = { ...@@ -984,7 +997,7 @@ admin.article = {
$("#loadMsg").text(Label.loadingLabel); $("#loadMsg").text(Label.loadingLabel);
$("#tipMsg").text(""); $("#tipMsg").text("");
var signId = ""; var signId = "";
$(".signs button").each(function () { $(".signs button").each(function() {
if (this.className === "selected") { if (this.className === "selected") {
signId = this.id.substr(this.id.length - 1, 1); signId = this.id.substr(this.id.length - 1, 1);
} }
...@@ -1013,10 +1026,15 @@ admin.article = { ...@@ -1013,10 +1026,15 @@ admin.article = {
type: "POST", type: "POST",
cache: false, cache: false,
data: JSON.stringify(requestJSONObject), data: JSON.stringify(requestJSONObject),
success: function(result, textStatus){ success: function(result, textStatus) {
if (isAuto) {
$("#tipMsg").text(Label.autoSaveLabel);
admin.article.status.id = result.oId;
return;
}
$("#tipMsg").text(result.msg); $("#tipMsg").text(result.msg);
if (!result.sc) { if (!result.sc) {
$("#loadMsg").text("");
return; return;
} }
...@@ -1028,11 +1046,10 @@ admin.article = { ...@@ -1028,11 +1046,10 @@ admin.article = {
} }
admin.article.isConfirm = false; admin.article.isConfirm = false;
$("#loadMsg").text("");
}, },
complete: function (jqXHR, textStatus){ complete: function(jqXHR, textStatus) {
that._removeDisabled(); that._removeDisabled();
$("#loadMsg").text("");
if (jqXHR.status === 403) { if (jqXHR.status === 403) {
$.get("/admin-index.do"); $.get("/admin-index.do");
that.add(articleIsPublished); that.add(articleIsPublished);
...@@ -1041,12 +1058,12 @@ admin.article = { ...@@ -1041,12 +1058,12 @@ admin.article = {
}); });
} }
}, },
/**
/* * @description 更新文章
* 更新文章 * @param {Boolean} articleIsPublished 文章是否发布过
* @articleIsPublished 文章是否发布过 * @param {Boolean} isAuto 是否为自动保存
*/ */
update: function (articleIsPublished) { update: function(articleIsPublished, isAuto) {
if (admin.article.validate()) { if (admin.article.validate()) {
var that = this; var that = this;
that._addDisabled(); that._addDisabled();
...@@ -1054,7 +1071,7 @@ admin.article = { ...@@ -1054,7 +1071,7 @@ admin.article = {
$("#loadMsg").text(Label.loadingLabel); $("#loadMsg").text(Label.loadingLabel);
$("#tipMsg").text(""); $("#tipMsg").text("");
var signId = ""; var signId = "";
$(".signs button").each(function () { $(".signs button").each(function() {
if (this.className === "selected") { if (this.className === "selected") {
signId = this.id.substr(this.id.length - 1, 1); signId = this.id.substr(this.id.length - 1, 1);
} }
...@@ -1084,14 +1101,18 @@ admin.article = { ...@@ -1084,14 +1101,18 @@ admin.article = {
type: "PUT", type: "PUT",
cache: false, cache: false,
data: JSON.stringify(requestJSONObject), data: JSON.stringify(requestJSONObject),
success: function(result, textStatus){ success: function(result, textStatus) {
if (isAuto) {
$("#tipMsg").text(Label.autoSaveLabel);
return;
}
$("#tipMsg").text(result.msg); $("#tipMsg").text(result.msg);
if (!result.sc) { if (!result.sc) {
$("#loadMsg").text("");
return; return;
} }
if (articleIsPublished){ if (articleIsPublished) {
admin.selectTab("article/article-list"); admin.selectTab("article/article-list");
} else { } else {
admin.selectTab("article/draft-list"); admin.selectTab("article/draft-list");
...@@ -1101,11 +1122,10 @@ admin.article = { ...@@ -1101,11 +1122,10 @@ admin.article = {
admin.article.status.id = undefined; admin.article.status.id = undefined;
admin.article.isConfirm = false; admin.article.isConfirm = false;
$("#loadMsg").text("");
}, },
complete: function (jqXHR, textStatus){ complete: function(jqXHR, textStatus) {
that._removeDisabled(); that._removeDisabled();
$("#loadMsg").text("");
if (jqXHR.status === 403) { if (jqXHR.status === 403) {
$.get("/admin-index.do"); $.get("/admin-index.do");
that.update(articleIsPublished); that.update(articleIsPublished);
...@@ -1114,11 +1134,10 @@ admin.article = { ...@@ -1114,11 +1134,10 @@ admin.article = {
}); });
} }
}, },
/**
/* * @description 发布文章页面设置文章按钮、发布到社区等状态的显示
* 发布文章页面设置文章按钮、发布到社区等状态的显示
*/ */
setStatus: function () { setStatus: function() {
// set button status // set button status
if (this.status) { if (this.status) {
if (this.status.isArticle) { if (this.status.isArticle) {
...@@ -1141,11 +1160,10 @@ admin.article = { ...@@ -1141,11 +1160,10 @@ admin.article = {
$("#postToCommunity").attr("checked", "checked"); $("#postToCommunity").attr("checked", "checked");
}, },
/**
/* * @description 清除发布文章页面的输入框的内容
* 清除发布文章页面的输入框的内容
*/ */
clear: function () { clear: function() {
this.status = { this.status = {
id: undefined, id: undefined,
isArticle: undefined, isArticle: undefined,
...@@ -1165,7 +1183,7 @@ admin.article = { ...@@ -1165,7 +1183,7 @@ admin.article = {
$("#permalink").val(""); $("#permalink").val("");
$("#articleCammentable").prop("checked", true); $("#articleCammentable").prop("checked", true);
$("#postToCommunity").prop("checked", true); $("#postToCommunity").prop("checked", true);
$(".signs button").each(function (i) { $(".signs button").each(function(i) {
if (i === 0) { if (i === 0) {
this.className = "selected"; this.className = "selected";
} else { } else {
...@@ -1175,37 +1193,38 @@ admin.article = { ...@@ -1175,37 +1193,38 @@ admin.article = {
$(".markdown-preview-main").html(""); $(".markdown-preview-main").html("");
}, },
/**
/* * @description 初始化发布文章页面
* 初始化发布文章页面 * @param {Function} fun 切面函数
*/ */
init: function (fun) { init: function(fun) {
// Inits Signs. // Inits Signs.
$.ajax({ $.ajax({
url: latkeConfig.servePath + "/console/signs/", url: latkeConfig.servePath + "/console/signs/",
type: "GET", type: "GET",
cache: false, cache: false,
success: function(result, textStatus){ success: function(result, textStatus) {
$("#tipMsg").text(result.msg); $("#tipMsg").text(result.msg);
if (!result.sc) { if (!result.sc) {
$("#loadMsg").text(""); $("#loadMsg").text("");
return; return;
} }
$(".signs button").each(function (i) { $(".signs button").each(function(i) {
// Sets signs. // Sets signs.
if (i === result.signs.length) { if (i === result.signs.length) {
$("#articleSign1").addClass("selected"); $("#articleSign1").addClass("selected");
} else { } else {
$("#articleSign" + result.signs[i].oId).tip({ $("#articleSign" + result.signs[i].oId).tip({
content: result.signs[i].signHTML === "" ? Label.signIsNullLabel : result.signs[i].signHTML.replace(/\n/g, "").replace(/<script.*<\/script>/ig, ""), content: result.signs[i].signHTML === "" ? Label.signIsNullLabel :
result.signs[i].signHTML.replace(/\n/g, "").replace(/<script.*<\/script>/ig, ""),
position: "top" position: "top"
}); });
} }
// Binds checkbox event. // Binds checkbox event.
$(this).click(function () { $(this).click(function() {
if (this.className !== "selected") { if (this.className !== "selected") {
$(".signs button").each(function () { $(".signs button").each(function() {
this.className = ""; this.className = "";
}); });
this.className = "selected"; this.className = "selected";
...@@ -1218,11 +1237,11 @@ admin.article = { ...@@ -1218,11 +1237,11 @@ admin.article = {
}); });
// For tag auto-completion // For tag auto-completion
$.ajax({ // Gets all tags $.ajax({// Gets all tags
url: latkeConfig.servePath + "/console/tags", url: latkeConfig.servePath + "/console/tags",
type: "GET", type: "GET",
cache: false, cache: false,
success: function(result, textStatus){ success: function(result, textStatus) {
$("#tipMsg").text(result.msg); $("#tipMsg").text(result.msg);
if (!result.sc) { if (!result.sc) {
$("#loadMsg").text(""); $("#loadMsg").text("");
...@@ -1249,7 +1268,7 @@ admin.article = { ...@@ -1249,7 +1268,7 @@ admin.article = {
}); });
// submit action // submit action
$("#submitArticle").click(function () { $("#submitArticle").click(function() {
if (admin.article.status.id) { if (admin.article.status.id) {
admin.article.update(true); admin.article.update(true);
} else { } else {
...@@ -1257,7 +1276,7 @@ admin.article = { ...@@ -1257,7 +1276,7 @@ admin.article = {
} }
}); });
$("#saveArticle").click(function () { $("#saveArticle").click(function() {
if (admin.article.status.id) { if (admin.article.status.id) {
admin.article.update(admin.article.status.isArticle); admin.article.update(admin.article.status.isArticle);
} else { } else {
...@@ -1278,12 +1297,47 @@ admin.article = { ...@@ -1278,12 +1297,47 @@ admin.article = {
kind: "simple", kind: "simple",
height: 200 height: 200
}); });
},
/* admin.article.clearDraftTimer();
* 验证发布文章字段的合法性 admin.article.autoSaveDraftTimer = setInterval(function() {
admin.article._autoSaveToDraft();
}, admin.article.AUTOSAVETIME);
},
/**
* @description 自动保存草稿件
*/ */
validate: function () { _autoSaveToDraft: function() {
if ($("#title").val().replace(/\s/g, "") === "" ||
admin.editors.articleEditor.getContent().replace(/\s/g, "") === "" ||
$("#tag").val().replace(/\s/g, "") === "") {
return;
}
if (admin.article.status.id) {
if (admin.article.status.isArticle) {
admin.article.status.isArticle = false;
admin.article.setStatus();
admin.article.unPublish(true);
} else {
admin.article.update(false, true);
}
} else {
admin.article.add(false, true);
admin.article.status.isArticle = false;
}
},
/**
* @description 关闭定时器
*/
clearDraftTimer: function() {
if (admin.article.autoSaveDraftTimer !== "") {
window.clearInterval(admin.article.autoSaveDraftTimer);
admin.article.autoSaveDraftTimer = "";
}
},
/**
* @description 验证发布文章字段的合法性
*/
validate: function() {
var articleContent = admin.editors.articleEditor.getContent(); var articleContent = admin.editors.articleEditor.getContent();
if ($("#title").val().replace(/\s/g, "") === "") { if ($("#title").val().replace(/\s/g, "") === "") {
...@@ -1299,22 +1353,25 @@ admin.article = { ...@@ -1299,22 +1353,25 @@ admin.article = {
} }
return false; return false;
}, },
/**
/* * @description 取消发布
* 取消发布 * @param {Boolean} isAuto 是否为自动保存
*/ */
unPublish: function () { unPublish: function(isAuto) {
var that = this; var that = this;
that._addDisabled(); that._addDisabled();
$.ajax({ $.ajax({
url: latkeConfig.servePath + "/console/article/unpublish/" + admin.article.status.id, url: latkeConfig.servePath + "/console/article/unpublish/" + admin.article.status.id,
type: "PUT", type: "PUT",
cache: false, cache: false,
success: function(result, textStatus){ success: function(result, textStatus) {
if (isAuto) {
$("#tipMsg").text(Label.autoSaveLabel);
return;
}
$("#tipMsg").text(result.msg); $("#tipMsg").text(result.msg);
if (!result.sc) { if (!result.sc) {
$("#loadMsg").text("");
return; return;
} }
...@@ -1322,8 +1379,9 @@ admin.article = { ...@@ -1322,8 +1379,9 @@ admin.article = {
admin.article.status.id = undefined; admin.article.status.id = undefined;
admin.article.isConfirm = false; admin.article.isConfirm = false;
}, },
complete: function (jqXHR, textStatus){ complete: function(jqXHR, textStatus) {
that._removeDisabled(); that._removeDisabled();
$("#loadMsg").text("");
if (jqXHR.status === 403) { if (jqXHR.status === 403) {
$.get("/admin-index.do"); $.get("/admin-index.do");
that.unPublish(); that.unPublish();
...@@ -1331,25 +1389,28 @@ admin.article = { ...@@ -1331,25 +1389,28 @@ admin.article = {
} }
}); });
}, },
/**
trimUniqueArray: function(str){ * @description 数组中无重复
* @param {String} str 被解析的字符串
* @returns {String} 无重复的字符串
*/
trimUniqueArray: function(str) {
str = str.toString(); str = str.toString();
var arr = str.split(","); var arr = str.split(",");
for(var i = 0; i < arr.length; i++) { for (var i = 0; i < arr.length; i++) {
arr[i] = arr[i].replace(/(^\s*)|(\s*$)/g,""); arr[i] = arr[i].replace(/(^\s*)|(\s*$)/g, "");
if( arr[i] === "" ){ if (arr[i] === "") {
arr.splice(i, 1); arr.splice(i, 1);
i-- i--;
} }
} }
var unique = $.unique(arr); var unique = $.unique(arr);
return unique.toString(); return unique.toString();
}, },
/**
/* * @description 点击发文文章时的处理
* 点击发文文章时的处理
*/ */
prePost: function () { prePost: function() {
$("#loadMsg").text(Label.loadingLabel); $("#loadMsg").text(Label.loadingLabel);
admin.article.content = ""; admin.article.content = "";
if (!admin.editors.articleEditor.getContent) { if (!admin.editors.articleEditor.getContent) {
...@@ -1367,34 +1428,31 @@ admin.article = { ...@@ -1367,34 +1428,31 @@ admin.article = {
$("#tipMsg").text(""); $("#tipMsg").text("");
$("#loadMsg").text(""); $("#loadMsg").text("");
}, },
/**
/*
* @description: 仿重复提交,点击一次后,按钮设置为 disabled * @description: 仿重复提交,点击一次后,按钮设置为 disabled
*/ */
_addDisabled: function () { _addDisabled: function() {
$("#unSubmitArticle").attr("disabled", "disabled"); $("#unSubmitArticle").attr("disabled", "disabled");
$("#saveArticle").attr("disabled", "disabled"); $("#saveArticle").attr("disabled", "disabled");
$("#submitArticle").attr("disabled", "disabled"); $("#submitArticle").attr("disabled", "disabled");
}, },
/**
/*
* @description: 仿重复提交,当后台有数据返回后,按钮移除 disabled 状态 * @description: 仿重复提交,当后台有数据返回后,按钮移除 disabled 状态
*/ */
_removeDisabled: function () { _removeDisabled: function() {
$("#unSubmitArticle").removeAttr("disabled"); $("#unSubmitArticle").removeAttr("disabled");
$("#saveArticle").removeAttr("disabled"); $("#saveArticle").removeAttr("disabled");
$("#submitArticle").removeAttr("disabled"); $("#submitArticle").removeAttr("disabled");
} }
};
} /**
* @description 注册到 admin 进行管理
/*
* 注册到 admin 进行管理
*/ */
admin.register.article = { admin.register.article = {
"obj": admin.article, "obj": admin.article,
"init": admin.article.init, "init": admin.article.init,
"refresh": function () { "refresh": function() {
$("#loadMsg").text(""); $("#loadMsg").text("");
$("#tipMsg").text(""); $("#tipMsg").text("");
} }
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment