Commit 4ccace5f authored by Vanessa's avatar Vanessa

about #261

parent 2cb43ac0
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
/**
* index for admin
* @description index for admin
*
* @author <a href="mailto:LLY219@gmail.com">Liyuan Li</a>
* @version 1.0.2.2, May 28, 2013
......@@ -30,8 +30,8 @@ var Admin = function() {
};
$.extend(Admin.prototype, {
/*
* 登出
/**
* @description 登出
*/
logout: function() {
window.location.href = latkeConfig.servePath + "/logout?goto=" + latkeConfig.servePath;
......@@ -43,9 +43,9 @@ $.extend(Admin.prototype, {
$("#tipMsg").text("");
$("#loadMsg").text("");
},
/*
* 根据当前页数设置 hash
* @currentPage {string} 当前页
/**
* @description 根据当前页数设置 hash
* @param {Int} currentPage 当前页
*/
setHashByPage: function(currentPage) {
var hash = window.location.hash,
......@@ -57,15 +57,15 @@ $.extend(Admin.prototype, {
}
window.location.hash = hashList.join("/");
},
/*
* 设置某个 tab 被选择
* @id tab id
/**
* @description 设置某个 tab 被选择
* @param {Stirng} id id tab id
*/
selectTab: function(id) {
window.location.hash = "#" + id;
},
/*
* 根据当前 hash 解析出当前页数及 hash 数组。
/**
* @description 根据当前 hash 解析出当前页数及 hash 数组。
*/
analyseHash: function() {
var hash = window.location.hash;
......@@ -83,8 +83,8 @@ $.extend(Admin.prototype, {
}
return tags;
},
/*
* 根据当前 hash 设置当前 tab
/**
* @description 根据当前 hash 设置当前 tab
*/
setCurByHash: function() {
$("#tipMsg").text("");
......@@ -100,6 +100,14 @@ $.extend(Admin.prototype, {
return;
}
if (tab !== "article") {
admin.article.clearDraftTimer();
} else if (tab === "article") {
admin.article.autoSaveDraftTimer = setInterval(function() {
admin.article._autoSaveToDraft();
}, admin.article.AUTOSAVETIME);
}
// 离开编辑器时进行提示
try {
// 除更新、发布、取消发布文章,编辑器中无内容外,离开编辑器需进行提示。
......@@ -191,8 +199,8 @@ $.extend(Admin.prototype, {
$("#loadMsg").text("");
}
},
/*
* 初始化整个后台
/**
* @description 初始化整个后台
*/
init: function() {
//window.onerror = Util.error;
......@@ -213,9 +221,9 @@ $.extend(Admin.prototype, {
}, 6000);
$("#loadMsg").text("");
},
/*
/**
* @description tools and article collapse
* @param {bom} it 触发事件对象
* @param {Bom} it 触发事件对象
*/
collapseNav: function(it) {
var subNav = $(it).next();
......@@ -227,8 +235,8 @@ $.extend(Admin.prototype, {
}
});
},
/*
* 后台及当前页面所需插件初始化完后,对权限进行控制及当前页面属于 tools 时,tools 选项需展开。
/**
* @description 后台及当前页面所需插件初始化完后,对权限进行控制及当前页面属于 tools 时,tools 选项需展开。
*/
inited: function() {
// Removes functions with the current user role
......
......@@ -29,6 +29,10 @@ admin.article = {
articleHadBeenPublished: undefined
},
content: "",
// 自动保存草稿定时器
autoSaveDraftTimer: "",
// 自动保存间隔
AUTOSAVETIME: 3000,
/**
* @description 获取文章并把值塞入发布文章页面
* @param {String} id 文章 id
......@@ -126,8 +130,9 @@ admin.article = {
/**
* @@description 添加文章
* @param {Boolean} articleIsPublished 文章是否发布过
* @param {Boolean} isAuto 是否为自动保存
*/
add: function(articleIsPublished) {
add: function(articleIsPublished, isAuto) {
if (admin.article.validate()) {
var that = this;
that._addDisabled();
......@@ -165,9 +170,14 @@ admin.article = {
cache: false,
data: JSON.stringify(requestJSONObject),
success: function(result, textStatus) {
if (isAuto) {
$("#tipMsg").text("TODO:");
admin.article.status.id = result.oId;
return;
}
$("#tipMsg").text(result.msg);
if (!result.sc) {
$("#loadMsg").text("");
return;
}
......@@ -179,11 +189,10 @@ admin.article = {
}
admin.article.isConfirm = false;
$("#loadMsg").text("");
},
complete: function(jqXHR, textStatus) {
that._removeDisabled();
$("#loadMsg").text("");
if (jqXHR.status === 403) {
$.get("/admin-index.do");
that.add(articleIsPublished);
......@@ -195,8 +204,9 @@ admin.article = {
/**
* @description 更新文章
* @param {Boolean} articleIsPublished 文章是否发布过
* @param {Boolean} isAuto 是否为自动保存
*/
update: function(articleIsPublished) {
update: function(articleIsPublished, isAuto) {
if (admin.article.validate()) {
var that = this;
that._addDisabled();
......@@ -235,9 +245,13 @@ admin.article = {
cache: false,
data: JSON.stringify(requestJSONObject),
success: function(result, textStatus) {
if (isAuto) {
$("#tipMsg").text("TODO:");
return;
}
$("#tipMsg").text(result.msg);
if (!result.sc) {
$("#loadMsg").text("");
return;
}
......@@ -251,11 +265,10 @@ admin.article = {
admin.article.status.id = undefined;
admin.article.isConfirm = false;
$("#loadMsg").text("");
},
complete: function(jqXHR, textStatus) {
that._removeDisabled();
$("#loadMsg").text("");
if (jqXHR.status === 403) {
$.get("/admin-index.do");
that.update(articleIsPublished);
......@@ -427,6 +440,41 @@ admin.article = {
kind: "simple",
height: 200
});
admin.article.clearDraftTimer();
admin.article.autoSaveDraftTimer = setInterval(function() {
admin.article._autoSaveToDraft();
}, admin.article.AUTOSAVETIME);
},
/**
* @description 自动保存草稿件
*/
_autoSaveToDraft: function() {
console.log("auto");
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.unPublish(true);
admin.article.status.isArticle = false;
} else {
admin.article.update(false, true);
}
} else {
admin.article.add(false, true);
}
},
/**
* @description 关闭定时器
*/
clearDraftTimer: function() {
if (admin.article.autoSaveDraftTimer !== "") {
window.clearInterval(admin.article.autoSaveDraftTimer);
admin.article.autoSaveDraftTimer = "";
}
},
/**
* @description 验证发布文章字段的合法性
......@@ -449,8 +497,9 @@ admin.article = {
},
/**
* @description 取消发布
* @param {Boolean} isAuto 是否为自动保存
*/
unPublish: function() {
unPublish: function(isAuto) {
var that = this;
that._addDisabled();
$.ajax({
......@@ -458,9 +507,13 @@ admin.article = {
type: "PUT",
cache: false,
success: function(result, textStatus) {
if (isAuto) {
$("#tipMsg").text("TODO:");
return;
}
$("#tipMsg").text(result.msg);
if (!result.sc) {
$("#loadMsg").text("");
return;
}
......@@ -470,6 +523,7 @@ admin.article = {
},
complete: function(jqXHR, textStatus) {
that._removeDisabled();
$("#loadMsg").text("");
if (jqXHR.status === 403) {
$.get("/admin-index.do");
that.unPublish();
......
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