Commit 2816991d authored by Vanessa's avatar Vanessa

about #261

parent 4ccace5f
......@@ -225,6 +225,7 @@ blogSubtitle1Label=Blog Subtitle:
blogHost1Label=Blog Host:
submmitCommentLabel=Commit Comment
saveLabel=Save
autoSaveLabel=Auto Save
tagLabel=Tag
tagsLabel=Tags
importedLabel=Imported
......
......@@ -225,6 +225,7 @@ blogSubtitle1Label=\u535a\u5ba2\u5b50\u6807\u9898\uff1a
blogHost1Label=\u535a\u5ba2\u5730\u5740\uff1a
submmitCommentLabel=\u63d0\u4ea4\u8bc4\u8bba
saveLabel=\u4fdd\u5b58
autoSaveLabel=\u81ea\u52a8\u4fdd\u5b58
tagLabel=\u6807\u7b7e
tagsLabel=\u6807\u7b7e
importedLabel=\u5df2\u5bfc\u5165
......
......@@ -114,7 +114,8 @@
"navLabel": "${navLabel}",
"userLabel": "${userLabel}",
"changeRoleLabel": "${changeRoleLabel}",
"visitorUserLabel": "${visitorUserLabel}"
"visitorUserLabel": "${visitorUserLabel}",
"autoSaveLabel": "${autoSaveLabel}"
};
admin.init();
......
......@@ -32,7 +32,7 @@ admin.article = {
// 自动保存草稿定时器
autoSaveDraftTimer: "",
// 自动保存间隔
AUTOSAVETIME: 3000,
AUTOSAVETIME: 1000 * 60,
/**
* @description 获取文章并把值塞入发布文章页面
* @param {String} id 文章 id
......@@ -171,7 +171,7 @@ admin.article = {
data: JSON.stringify(requestJSONObject),
success: function(result, textStatus) {
if (isAuto) {
$("#tipMsg").text("TODO:");
$("#tipMsg").text(Label.autoSaveLabel);
admin.article.status.id = result.oId;
return;
}
......@@ -246,7 +246,7 @@ admin.article = {
data: JSON.stringify(requestJSONObject),
success: function(result, textStatus) {
if (isAuto) {
$("#tipMsg").text("TODO:");
$("#tipMsg").text(Label.autoSaveLabel);
return;
}
......@@ -450,7 +450,6 @@ admin.article = {
* @description 自动保存草稿件
*/
_autoSaveToDraft: function() {
console.log("auto");
if ($("#title").val().replace(/\s/g, "") === "" ||
admin.editors.articleEditor.getContent().replace(/\s/g, "") === "" ||
$("#tag").val().replace(/\s/g, "") === "") {
......@@ -458,13 +457,15 @@ admin.article = {
}
if (admin.article.status.id) {
if (admin.article.status.isArticle) {
admin.article.unPublish(true);
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;
}
},
/**
......@@ -508,7 +509,7 @@ admin.article = {
cache: false,
success: function(result, textStatus) {
if (isAuto) {
$("#tipMsg").text("TODO:");
$("#tipMsg").text(Label.autoSaveLabel);
return;
}
......
......@@ -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
......@@ -867,7 +875,7 @@ $.extend(TablePaginate.prototype, {
*
* @author <a href="mailto:LLY219@gmail.com">Liyuan Li</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 = {
// 当发文章,取消发布,更新文章时设置为 false。不需在离开编辑器时进行提示。
......@@ -878,41 +886,47 @@ admin.article = {
articleHadBeenPublished: undefined
},
content: "",
/*
* 获取文章并把值塞入发布文章页面
* @id 文章 id
* @isArticle 文章或者草稿
// 自动保存草稿定时器
autoSaveDraftTimer: "",
// 自动保存间隔
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.isArticle = isArticle
this.status.isArticle = isArticle;
admin.selectTab("article/article");
},
getAndSet: function () {
/**
* @description 获取文章内容
*/
getAndSet: function() {
$("#loadMsg").text(Label.loadingLabel);
$("#tipMsg").text("");
$.ajax({
url: latkeConfig.servePath + "/console/article/" + admin.article.status.id,
type: "GET",
cache: false,
success: function(result, textStatus){
success: function(result, textStatus) {
$("#tipMsg").text(result.msg);
if (!result.sc) {
$("#loadMsg").text("");
return;
}
// set default value for article.
$("#title").val(result.article.articleTitle);
admin.article.status.articleHadBeenPublished = result.article.articleHadBeenPublished;
admin.article.status.articleHadBeenPublished = result.article.articleHadBeenPublished;
admin.editors.articleEditor.setContent(result.article.articleContent);
admin.editors.abstractEditor.setContent(result.article.articleAbstract);
admin.article.content = admin.editors.articleEditor.getContent();
var tags = result.article.articleTags,
tagsString = '';
tagsString = '';
for (var i = 0; i < tags.length; i++) {
if (0 === i) {
tagsString = tags[i].tagTitle;
......@@ -920,16 +934,16 @@ admin.article = {
tagsString += "," + tags[i].tagTitle;
}
}
$("#tag").val(tagsString);
$("#permalink").val(result.article.articlePermalink);
$("#viewPwd").val(result.article.articleViewPwd);
$("#articleCommentable").prop("checked", result.article.articleCommentable);
// 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)) {
$("#articleSign" + signs[i].oId).addClass("selected");
} else {
......@@ -942,57 +956,56 @@ admin.article = {
}
});
},
/*
* 删除文章
* @id 文章 id
* @fromId 文章来自草稿夹(draft)/文件夹(article)
* @title 文章标题
/**
* @description 删除文章
* @param {String} id 文章 id
* @param {String} fromId 文章来自草稿夹(draft)/文件夹(article)
* @param {String} title 文章标题
*/
del: function (id, fromId, title) {
del: function(id, fromId, title) {
var isDelete = confirm(Label.confirmRemoveLabel + Label.articleLabel + '"' + title + '"?');
if (isDelete) {
$("#loadMsg").text(Label.loadingLabel);
$("#tipMsg").text("");
$.ajax({
url: latkeConfig.servePath + "/console/article/" + id,
type: "DELETE",
cache: false,
success: function(result, textStatus){
success: function(result, textStatus) {
$("#tipMsg").text(result.msg);
if (!result.sc) {
$("#loadMsg").text("");
return;
}
admin[fromId + "List"].getList(1);
}
});
}
},
/*
* 添加文章
* @articleIsPublished 文章是否发布过
/**
* @@description 添加文章
* @param {Boolean} articleIsPublished 文章是否发布过
* @param {Boolean} isAuto 是否为自动保存
*/
add: function (articleIsPublished) {
add: function(articleIsPublished, isAuto) {
if (admin.article.validate()) {
var that = this;
that._addDisabled();
$("#loadMsg").text(Label.loadingLabel);
$("#tipMsg").text("");
var signId = "";
$(".signs button").each(function () {
$(".signs button").each(function() {
if (this.className === "selected") {
signId = this.id.substr(this.id.length - 1, 1);
}
});
var articleContent = admin.editors.articleEditor.getContent(),
articleAbstract = admin.editors.abstractEditor.getContent();
articleAbstract = admin.editors.abstractEditor.getContent();
var requestJSONObject = {
"article": {
"articleTitle": $("#title").val(),
......@@ -1007,32 +1020,36 @@ admin.article = {
"articleViewPwd": $("#viewPwd").val()
}
};
$.ajax({
url: latkeConfig.servePath + "/console/article/",
type: "POST",
cache: false,
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);
if (!result.sc) {
$("#loadMsg").text("");
return;
}
if (articleIsPublished) {
admin.article.status.id = undefined;
admin.selectTab("article/article-list");
} else {
admin.selectTab("article/draft-list");
}
admin.article.isConfirm = false;
$("#loadMsg").text("");
},
complete: function (jqXHR, textStatus){
complete: function(jqXHR, textStatus) {
that._removeDisabled();
$("#loadMsg").text("");
if (jqXHR.status === 403) {
$.get("/admin-index.do");
that.add(articleIsPublished);
......@@ -1041,28 +1058,28 @@ admin.article = {
});
}
},
/*
* 更新文章
* @articleIsPublished 文章是否发布过
/**
* @description 更新文章
* @param {Boolean} articleIsPublished 文章是否发布过
* @param {Boolean} isAuto 是否为自动保存
*/
update: function (articleIsPublished) {
update: function(articleIsPublished, isAuto) {
if (admin.article.validate()) {
var that = this;
that._addDisabled();
$("#loadMsg").text(Label.loadingLabel);
$("#tipMsg").text("");
var signId = "";
$(".signs button").each(function () {
$(".signs button").each(function() {
if (this.className === "selected") {
signId = this.id.substr(this.id.length - 1, 1);
}
});
var articleContent = admin.editors.articleEditor.getContent(),
articleAbstract = admin.editors.abstractEditor.getContent();
articleAbstract = admin.editors.abstractEditor.getContent();
var requestJSONObject = {
"article": {
"oId": this.status.id,
......@@ -1078,34 +1095,37 @@ admin.article = {
"postToCommunity": $("#postToCommunity").prop("checked")
}
};
$.ajax({
url: latkeConfig.servePath + "/console/article/",
type: "PUT",
cache: false,
data: JSON.stringify(requestJSONObject),
success: function(result, textStatus){
success: function(result, textStatus) {
if (isAuto) {
$("#tipMsg").text(Label.autoSaveLabel);
return;
}
$("#tipMsg").text(result.msg);
if (!result.sc) {
$("#loadMsg").text("");
return;
}
if (articleIsPublished){
if (articleIsPublished) {
admin.selectTab("article/article-list");
} else {
admin.selectTab("article/draft-list");
}
$("#tipMsg").text(Label.updateSuccLabel);
admin.article.status.id = undefined;
admin.article.isConfirm = false;
$("#loadMsg").text("");
},
complete: function (jqXHR, textStatus){
complete: function(jqXHR, textStatus) {
that._removeDisabled();
$("#loadMsg").text("");
if (jqXHR.status === 403) {
$.get("/admin-index.do");
that.update(articleIsPublished);
......@@ -1114,14 +1134,13 @@ admin.article = {
});
}
},
/*
* 发布文章页面设置文章按钮、发布到社区等状态的显示
/**
* @description 发布文章页面设置文章按钮、发布到社区等状态的显示
*/
setStatus: function () {
setStatus: function() {
// set button status
if (this.status) {
if (this.status.isArticle) {
if (this.status.isArticle) {
$("#unSubmitArticle").show();
$("#submitArticle").hide();
} else {
......@@ -1141,123 +1160,123 @@ admin.article = {
$("#postToCommunity").attr("checked", "checked");
},
/*
* 清除发布文章页面的输入框的内容
/**
* @description 清除发布文章页面的输入框的内容
*/
clear: function () {
clear: function() {
this.status = {
id: undefined,
isArticle: undefined,
articleHadBeenPublished: undefined
};
this.setStatus();
$("#title").val("");
admin.editors.articleEditor.setContent("");
admin.editors.abstractEditor.setContent("");
// reset tag
$("#tag").val("");
$("#tagCheckboxPanel").hide().find("span").removeClass("selected");
$("#permalink").val("");
$("#articleCammentable").prop("checked", true);
$("#postToCommunity").prop("checked", true);
$(".signs button").each(function (i) {
$(".signs button").each(function(i) {
if (i === 0) {
this.className = "selected";
} else {
this.className = "";
}
});
$(".markdown-preview-main").html("");
},
/*
* 初始化发布文章页面
/**
* @description 初始化发布文章页面
* @param {Function} fun 切面函数
*/
init: function (fun) {
init: function(fun) {
// Inits Signs.
$.ajax({
url: latkeConfig.servePath + "/console/signs/",
type: "GET",
cache: false,
success: function(result, textStatus){
success: function(result, textStatus) {
$("#tipMsg").text(result.msg);
if (!result.sc) {
$("#loadMsg").text("");
return;
}
$(".signs button").each(function (i) {
$(".signs button").each(function(i) {
// Sets signs.
if (i === result.signs.length) {
$("#articleSign1").addClass("selected");
} else {
$("#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"
});
}
// Binds checkbox event.
$(this).click(function () {
$(this).click(function() {
if (this.className !== "selected") {
$(".signs button").each(function () {
$(".signs button").each(function() {
this.className = "";
});
this.className = "selected";
}
});
});
$("#loadMsg").text("");
}
});
// For tag auto-completion
$.ajax({ // Gets all tags
$.ajax({// Gets all tags
url: latkeConfig.servePath + "/console/tags",
type: "GET",
cache: false,
success: function(result, textStatus){
success: function(result, textStatus) {
$("#tipMsg").text(result.msg);
if (!result.sc) {
$("#loadMsg").text("");
return;
}
if (0 >= result.tags.length) {
return;
}
var tags = [];
for (var i = 0; i < result.tags.length; i++) {
tags.push(result.tags[i].tagTitle);
}
$("#tag").completed({
height: 160,
buttonText: Label.selectLabel,
data: tags
});
$("#loadMsg").text("");
}
});
// submit action
$("#submitArticle").click(function () {
$("#submitArticle").click(function() {
if (admin.article.status.id) {
admin.article.update(true);
} else {
admin.article.add(true);
}
});
$("#saveArticle").click(function () {
$("#saveArticle").click(function() {
if (admin.article.status.id) {
admin.article.update(admin.article.status.isArticle);
} else {
......@@ -1272,20 +1291,55 @@ admin.article = {
fun: fun,
height: 500
});
admin.editors.abstractEditor = new Editor({
id: "abstract",
kind: "simple",
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();
if ($("#title").val().replace(/\s/g, "") === "") {
$("#tipMsg").text(Label.titleEmptyLabel);
$("#title").focus().val("");
......@@ -1299,31 +1353,35 @@ admin.article = {
}
return false;
},
/*
* 取消发布
/**
* @description 取消发布
* @param {Boolean} isAuto 是否为自动保存
*/
unPublish: function () {
unPublish: function(isAuto) {
var that = this;
that._addDisabled();
$.ajax({
url: latkeConfig.servePath + "/console/article/unpublish/" + admin.article.status.id,
type: "PUT",
cache: false,
success: function(result, textStatus){
success: function(result, textStatus) {
if (isAuto) {
$("#tipMsg").text(Label.autoSaveLabel);
return;
}
$("#tipMsg").text(result.msg);
if (!result.sc) {
$("#loadMsg").text("");
return;
}
admin.selectTab("article/draft-list");
admin.article.status.id = undefined;
admin.article.isConfirm = false;
},
complete: function (jqXHR, textStatus){
complete: function(jqXHR, textStatus) {
that._removeDisabled();
$("#loadMsg").text("");
if (jqXHR.status === 403) {
$.get("/admin-index.do");
that.unPublish();
......@@ -1331,35 +1389,38 @@ admin.article = {
}
});
},
trimUniqueArray: function(str){
/**
* @description 数组中无重复
* @param {String} str 被解析的字符串
* @returns {String} 无重复的字符串
*/
trimUniqueArray: function(str) {
str = str.toString();
var arr = str.split(",");
for(var i = 0; i < arr.length; i++) {
arr[i] = arr[i].replace(/(^\s*)|(\s*$)/g,"");
if( arr[i] === "" ){
for (var i = 0; i < arr.length; i++) {
arr[i] = arr[i].replace(/(^\s*)|(\s*$)/g, "");
if (arr[i] === "") {
arr.splice(i, 1);
i--
i--;
}
}
var unique = $.unique(arr);
var unique = $.unique(arr);
return unique.toString();
},
/*
* 点击发文文章时的处理
/**
* @description 点击发文文章时的处理
*/
prePost: function () {
prePost: function() {
$("#loadMsg").text(Label.loadingLabel);
admin.article.content = "";
if (!admin.editors.articleEditor.getContent) {
return;
}
var articleContent = admin.editors.articleEditor.getContent();
if (window.location.hash === "#article/article" &&
articleContent.replace(/\s/g, '') !== "") {
if (window.location.hash === "#article/article" &&
articleContent.replace(/\s/g, '') !== "") {
if (confirm(Label.editorPostLabel)) {
admin.article.clear();
}
......@@ -1367,34 +1428,31 @@ admin.article = {
$("#tipMsg").text("");
$("#loadMsg").text("");
},
/*
/**
* @description: 仿重复提交,点击一次后,按钮设置为 disabled
*/
_addDisabled: function () {
_addDisabled: function() {
$("#unSubmitArticle").attr("disabled", "disabled");
$("#saveArticle").attr("disabled", "disabled");
$("#submitArticle").attr("disabled", "disabled");
},
/*
/**
* @description: 仿重复提交,当后台有数据返回后,按钮移除 disabled 状态
*/
_removeDisabled: function () {
_removeDisabled: function() {
$("#unSubmitArticle").removeAttr("disabled");
$("#saveArticle").removeAttr("disabled");
$("#submitArticle").removeAttr("disabled");
}
}
};
/*
* 注册到 admin 进行管理
/**
* @description 注册到 admin 进行管理
*/
admin.register.article = {
admin.register.article = {
"obj": admin.article,
"init": admin.article.init,
"refresh": function () {
"refresh": function() {
$("#loadMsg").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