Commit ee7df903 authored by Liang Ding's avatar Liang Ding

格式化

parent b8464070
...@@ -27,10 +27,10 @@ import org.b3log.latke.mail.MailServiceFactory; ...@@ -27,10 +27,10 @@ import org.b3log.latke.mail.MailServiceFactory;
import org.b3log.latke.util.Strings; import org.b3log.latke.util.Strings;
import org.b3log.solo.SoloServletListener; import org.b3log.solo.SoloServletListener;
import org.b3log.solo.event.EventTypes; import org.b3log.solo.event.EventTypes;
import org.b3log.solo.model.Article;
import org.b3log.solo.model.Comment; import org.b3log.solo.model.Comment;
import org.b3log.solo.model.Preference; import org.b3log.solo.model.Preference;
import org.b3log.solo.repository.CommentRepository; import org.b3log.solo.repository.CommentRepository;
import org.b3log.solo.model.Article;
import org.b3log.solo.repository.impl.CommentRepositoryImpl; import org.b3log.solo.repository.impl.CommentRepositoryImpl;
import org.b3log.solo.service.PreferenceQueryService; import org.b3log.solo.service.PreferenceQueryService;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -39,22 +39,19 @@ import org.json.JSONObject; ...@@ -39,22 +39,19 @@ import org.json.JSONObject;
* This listener is responsible for processing article comment reply. * This listener is responsible for processing article comment reply.
* *
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a> * @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.1.4, Oct 31, 2011 * @version 1.0.1.5, Dec 13, 2012
* @since 0.3.1 * @since 0.3.1
*/ */
public final class ArticleCommentReplyNotifier public final class ArticleCommentReplyNotifier extends AbstractEventListener<JSONObject> {
extends AbstractEventListener<JSONObject> {
/** /**
* Logger. * Logger.
*/ */
private static final Logger LOGGER = private static final Logger LOGGER = Logger.getLogger(ArticleCommentReplyNotifier.class.getName());
Logger.getLogger(ArticleCommentReplyNotifier.class.getName());
/** /**
* Comment repository. * Comment repository.
*/ */
private CommentRepository commentRepository = private CommentRepository commentRepository = CommentRepositoryImpl.getInstance();
CommentRepositoryImpl.getInstance();
/** /**
* Mail service. * Mail service.
*/ */
...@@ -62,33 +59,25 @@ public final class ArticleCommentReplyNotifier ...@@ -62,33 +59,25 @@ public final class ArticleCommentReplyNotifier
/** /**
* Preference query service. * Preference query service.
*/ */
private PreferenceQueryService preferenceQueryService = private PreferenceQueryService preferenceQueryService = PreferenceQueryService.getInstance();
PreferenceQueryService.getInstance();
@Override @Override
public void action(final Event<JSONObject> event) throws EventException { public void action(final Event<JSONObject> event) throws EventException {
final JSONObject eventData = event.getData(); final JSONObject eventData = event.getData();
final JSONObject comment = eventData.optJSONObject(Comment.COMMENT); final JSONObject comment = eventData.optJSONObject(Comment.COMMENT);
final JSONObject article = eventData.optJSONObject(Article.ARTICLE); final JSONObject article = eventData.optJSONObject(Article.ARTICLE);
LOGGER.log(Level.FINER, LOGGER.log(Level.FINER, "Processing an event[type={0}, data={1}] in listener[className={2}]",
"Processing an event[type={0}, data={1}] in listener[className={2}]", new Object[]{event.getType(), eventData, ArticleCommentReplyNotifier.class.getName()});
new Object[]{event.getType(), final String originalCommentId = comment.optString(Comment.COMMENT_ORIGINAL_COMMENT_ID);
eventData,
ArticleCommentReplyNotifier.class.getName()});
final String originalCommentId =
comment.optString(Comment.COMMENT_ORIGINAL_COMMENT_ID);
if (Strings.isEmptyOrNull(originalCommentId)) { if (Strings.isEmptyOrNull(originalCommentId)) {
LOGGER.log(Level.FINER, "This comment[id={0}] is not a reply", LOGGER.log(Level.FINER, "This comment[id={0}] is not a reply", comment.optString(Keys.OBJECT_ID));
comment.optString(Keys.OBJECT_ID));
return; return;
} }
try { try {
final String commentEmail = comment.getString(Comment.COMMENT_EMAIL); final String commentEmail = comment.getString(Comment.COMMENT_EMAIL);
final JSONObject originalComment = final JSONObject originalComment = commentRepository.get(originalCommentId);
commentRepository.get(originalCommentId); final String originalCommentEmail = originalComment.getString(Comment.COMMENT_EMAIL);
final String originalCommentEmail =
originalComment.getString(Comment.COMMENT_EMAIL);
if (originalCommentEmail.equalsIgnoreCase(commentEmail)) { if (originalCommentEmail.equalsIgnoreCase(commentEmail)) {
return; return;
} }
...@@ -98,34 +87,25 @@ public final class ArticleCommentReplyNotifier ...@@ -98,34 +87,25 @@ public final class ArticleCommentReplyNotifier
throw new EventException("Not found preference"); throw new EventException("Not found preference");
} }
final String blogTitle = final String blogTitle = preference.getString(Preference.BLOG_TITLE);
preference.getString(Preference.BLOG_TITLE); final String adminEmail = preference.getString(Preference.ADMIN_EMAIL);
final String adminEmail =
preference.getString(Preference.ADMIN_EMAIL);
final String commentContent = final String commentContent = comment.getString(Comment.COMMENT_CONTENT).replaceAll(SoloServletListener.ENTER_ESC, "<br/>");
comment.getString(Comment.COMMENT_CONTENT). final String commentSharpURL = comment.getString(Comment.COMMENT_SHARP_URL);
replaceAll(SoloServletListener.ENTER_ESC, "<br/>");
final String commentSharpURL =
comment.getString(Comment.COMMENT_SHARP_URL);
final Message message = new Message(); final Message message = new Message();
message.setFrom(adminEmail); message.setFrom(adminEmail);
message.addRecipient(originalCommentEmail); message.addRecipient(originalCommentEmail);
final JSONObject replyNotificationTemplate = final JSONObject replyNotificationTemplate = preferenceQueryService.getReplyNotificationTemplate();
preferenceQueryService.getReplyNotificationTemplate(); final String mailSubject = replyNotificationTemplate.getString("subject").replace("${blogTitle}", blogTitle);
final String mailSubject = replyNotificationTemplate.getString(
"subject").replace("${blogTitle}", blogTitle);
message.setSubject(mailSubject); message.setSubject(mailSubject);
final String articleTitle = article.getString(Article.ARTICLE_TITLE); final String articleTitle = article.getString(Article.ARTICLE_TITLE);
final String blogHost = preference.getString(Preference.BLOG_HOST); final String blogHost = preference.getString(Preference.BLOG_HOST);
final String articleLink = "http://" + blogHost + article.getString( final String articleLink = "http://" + blogHost + article.getString(Article.ARTICLE_PERMALINK);
Article.ARTICLE_PERMALINK);
final String commentName = comment.getString(Comment.COMMENT_NAME); final String commentName = comment.getString(Comment.COMMENT_NAME);
final String commentURL = comment.getString(Comment.COMMENT_URL); final String commentURL = comment.getString(Comment.COMMENT_URL);
String commenter = null; String commenter;
if (!"http://".equals(commentURL)) { if (!"http://".equals(commentURL)) {
commenter = "<a target=\"_blank\" " + "href=\"" + commentURL commenter = "<a target=\"_blank\" " + "href=\"" + commentURL + "\">" + commentName + "</a>";
+ "\">" + commentName + "</a>";
} else { } else {
commenter = commentName; commenter = commentName;
} }
...@@ -135,13 +115,11 @@ public final class ArticleCommentReplyNotifier ...@@ -135,13 +115,11 @@ public final class ArticleCommentReplyNotifier
replace("${postTitle}", articleTitle). replace("${postTitle}", articleTitle).
replace("${replier}", commenter). replace("${replier}", commenter).
replace("${replyURL}", "http://" + blogHost replace("${replyURL}", "http://" + blogHost
+ commentSharpURL). + commentSharpURL).
replace("${replyContent}", commentContent); replace("${replyContent}", commentContent);
message.setHtmlBody(mailBody); message.setHtmlBody(mailBody);
LOGGER.log(Level.FINER, LOGGER.log(Level.FINER, "Sending a mail[mailSubject={0}, mailBody=[{1}] to [{2}]",
"Sending a mail[mailSubject={0}, mailBody=[{1}] to [{2}]", new Object[]{mailSubject, mailBody, originalCommentEmail});
new Object[]{mailSubject, mailBody,
originalCommentEmail});
mailService.send(message); mailService.send(message);
} catch (final Exception e) { } catch (final Exception e) {
......
...@@ -28,9 +28,9 @@ import org.b3log.latke.util.Strings; ...@@ -28,9 +28,9 @@ import org.b3log.latke.util.Strings;
import org.b3log.solo.SoloServletListener; import org.b3log.solo.SoloServletListener;
import org.b3log.solo.event.EventTypes; import org.b3log.solo.event.EventTypes;
import org.b3log.solo.model.Comment; import org.b3log.solo.model.Comment;
import org.b3log.solo.model.Page;
import org.b3log.solo.model.Preference; import org.b3log.solo.model.Preference;
import org.b3log.solo.repository.CommentRepository; import org.b3log.solo.repository.CommentRepository;
import org.b3log.solo.model.Page;
import org.b3log.solo.repository.impl.CommentRepositoryImpl; import org.b3log.solo.repository.impl.CommentRepositoryImpl;
import org.b3log.solo.service.PreferenceQueryService; import org.b3log.solo.service.PreferenceQueryService;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -42,19 +42,16 @@ import org.json.JSONObject; ...@@ -42,19 +42,16 @@ import org.json.JSONObject;
* @version 1.0.1.1, Oct 31, 2011 * @version 1.0.1.1, Oct 31, 2011
* @since 0.3.1 * @since 0.3.1
*/ */
public final class PageCommentReplyNotifier public final class PageCommentReplyNotifier extends AbstractEventListener<JSONObject> {
extends AbstractEventListener<JSONObject> {
/** /**
* Logger. * Logger.
*/ */
private static final Logger LOGGER = private static final Logger LOGGER = Logger.getLogger(PageCommentReplyNotifier.class.getName());
Logger.getLogger(PageCommentReplyNotifier.class.getName());
/** /**
* Comment repository. * Comment repository.
*/ */
private CommentRepository commentRepository = private CommentRepository commentRepository = CommentRepositoryImpl.getInstance();
CommentRepositoryImpl.getInstance();
/** /**
* Mail service. * Mail service.
*/ */
...@@ -62,33 +59,25 @@ public final class PageCommentReplyNotifier ...@@ -62,33 +59,25 @@ public final class PageCommentReplyNotifier
/** /**
* Preference query service. * Preference query service.
*/ */
private PreferenceQueryService preferenceQueryService = private PreferenceQueryService preferenceQueryService = PreferenceQueryService.getInstance();
PreferenceQueryService.getInstance();
@Override @Override
public void action(final Event<JSONObject> event) throws EventException { public void action(final Event<JSONObject> event) throws EventException {
final JSONObject eventData = event.getData(); final JSONObject eventData = event.getData();
final JSONObject comment = eventData.optJSONObject(Comment.COMMENT); final JSONObject comment = eventData.optJSONObject(Comment.COMMENT);
final JSONObject page = eventData.optJSONObject(Page.PAGE); final JSONObject page = eventData.optJSONObject(Page.PAGE);
LOGGER.log(Level.FINER, LOGGER.log(Level.FINER, "Processing an event[type={0}, data={1}] in listener[className={2}]",
"Processing an event[type={0}, data={1}] in listener[className={2}]", new Object[]{event.getType(), eventData, PageCommentReplyNotifier.class.getName()});
new Object[]{event.getType(), final String originalCommentId = comment.optString(Comment.COMMENT_ORIGINAL_COMMENT_ID);
eventData,
PageCommentReplyNotifier.class.getName()});
final String originalCommentId =
comment.optString(Comment.COMMENT_ORIGINAL_COMMENT_ID);
if (Strings.isEmptyOrNull(originalCommentId)) { if (Strings.isEmptyOrNull(originalCommentId)) {
LOGGER.log(Level.FINER, "This comment[id={0}] is not a reply", LOGGER.log(Level.FINER, "This comment[id={0}] is not a reply", comment.optString(Keys.OBJECT_ID));
comment.optString(Keys.OBJECT_ID));
return; return;
} }
try { try {
final String commentEmail = comment.getString(Comment.COMMENT_EMAIL); final String commentEmail = comment.getString(Comment.COMMENT_EMAIL);
final JSONObject originalComment = final JSONObject originalComment = commentRepository.get(originalCommentId);
commentRepository.get(originalCommentId); final String originalCommentEmail = originalComment.getString(Comment.COMMENT_EMAIL);
final String originalCommentEmail =
originalComment.getString(Comment.COMMENT_EMAIL);
if (originalCommentEmail.equalsIgnoreCase(commentEmail)) { if (originalCommentEmail.equalsIgnoreCase(commentEmail)) {
return; return;
} }
...@@ -98,34 +87,26 @@ public final class PageCommentReplyNotifier ...@@ -98,34 +87,26 @@ public final class PageCommentReplyNotifier
throw new EventException("Not found preference"); throw new EventException("Not found preference");
} }
final String blogTitle = final String blogTitle = preference.getString(Preference.BLOG_TITLE);
preference.getString(Preference.BLOG_TITLE); final String adminEmail = preference.getString(Preference.ADMIN_EMAIL);
final String adminEmail =
preference.getString(Preference.ADMIN_EMAIL);
final String commentContent = final String commentContent = comment.getString(Comment.COMMENT_CONTENT).
comment.getString(Comment.COMMENT_CONTENT).
replaceAll(SoloServletListener.ENTER_ESC, "<br/>"); replaceAll(SoloServletListener.ENTER_ESC, "<br/>");
final String commentSharpURL = final String commentSharpURL = comment.getString(Comment.COMMENT_SHARP_URL);
comment.getString(Comment.COMMENT_SHARP_URL);
final Message message = new Message(); final Message message = new Message();
message.setFrom(adminEmail); message.setFrom(adminEmail);
message.addRecipient(originalCommentEmail); message.addRecipient(originalCommentEmail);
final JSONObject replyNotificationTemplate = final JSONObject replyNotificationTemplate = preferenceQueryService.getReplyNotificationTemplate();
preferenceQueryService.getReplyNotificationTemplate(); final String mailSubject = replyNotificationTemplate.getString("subject").replace("${blogTitle}", blogTitle);
final String mailSubject = replyNotificationTemplate.getString(
"subject").replace("${blogTitle}", blogTitle);
message.setSubject(mailSubject); message.setSubject(mailSubject);
final String pageTitle = page.getString(Page.PAGE_TITLE); final String pageTitle = page.getString(Page.PAGE_TITLE);
final String blogHost = preference.getString(Preference.BLOG_HOST); final String blogHost = preference.getString(Preference.BLOG_HOST);
final String pageLink = "http://" + blogHost final String pageLink = "http://" + blogHost + page.getString(Page.PAGE_PERMALINK);
+ page.getString(Page.PAGE_PERMALINK);
final String commentName = comment.getString(Comment.COMMENT_NAME); final String commentName = comment.getString(Comment.COMMENT_NAME);
final String commentURL = comment.getString(Comment.COMMENT_URL); final String commentURL = comment.getString(Comment.COMMENT_URL);
String commenter = null; String commenter;
if (!"http://".equals(commentURL)) { if (!"http://".equals(commentURL)) {
commenter = "<a target=\"_blank\" " + "href=\"" + commentURL commenter = "<a target=\"_blank\" " + "href=\"" + commentURL + "\">" + commentName + "</a>";
+ "\">" + commentName + "</a>";
} else { } else {
commenter = commentName; commenter = commentName;
} }
...@@ -135,13 +116,11 @@ public final class PageCommentReplyNotifier ...@@ -135,13 +116,11 @@ public final class PageCommentReplyNotifier
replace("${postTitle}", pageTitle). replace("${postTitle}", pageTitle).
replace("${replier}", commenter). replace("${replier}", commenter).
replace("${replyURL}", "http://" + blogHost replace("${replyURL}", "http://" + blogHost
+ commentSharpURL). + commentSharpURL).
replace("${replyContent}", commentContent); replace("${replyContent}", commentContent);
message.setHtmlBody(mailBody); message.setHtmlBody(mailBody);
LOGGER.log(Level.FINER, LOGGER.log(Level.FINER, "Sending a mail[mailSubject={0}, mailBody=[{1}] to [{2}]",
"Sending a mail[mailSubject={0}, mailBody=[{1}] to [{2}]", new Object[]{mailSubject, mailBody, originalCommentEmail});
new Object[]{mailSubject, mailBody,
originalCommentEmail});
mailService.send(message); mailService.send(message);
} catch (final Exception e) { } catch (final Exception e) {
LOGGER.log(Level.SEVERE, e.getMessage(), e); LOGGER.log(Level.SEVERE, e.getMessage(), e);
......
...@@ -163,7 +163,7 @@ public final class CommentMgmtService { ...@@ -163,7 +163,7 @@ public final class CommentMgmtService {
ret.put(Comment.COMMENT_ORIGINAL_COMMENT_NAME, originalCommentName); ret.put(Comment.COMMENT_ORIGINAL_COMMENT_NAME, originalCommentName);
} else { } else {
LOGGER.log(Level.WARNING, "Not found orginal comment[id={0}] of reply[name={1}, content={2}]", LOGGER.log(Level.WARNING, "Not found orginal comment[id={0}] of reply[name={1}, content={2}]",
new String[]{originalCommentId, commentName, commentContent}); new String[]{originalCommentId, commentName, commentContent});
} }
} }
setCommentThumbnailURL(comment); setCommentThumbnailURL(comment);
...@@ -276,7 +276,7 @@ public final class CommentMgmtService { ...@@ -276,7 +276,7 @@ public final class CommentMgmtService {
ret.put(Comment.COMMENT_ORIGINAL_COMMENT_NAME, originalCommentName); ret.put(Comment.COMMENT_ORIGINAL_COMMENT_NAME, originalCommentName);
} else { } else {
LOGGER.log(Level.WARNING, "Not found orginal comment[id={0}] of reply[name={1}, content={2}]", LOGGER.log(Level.WARNING, "Not found orginal comment[id={0}] of reply[name={1}, content={2}]",
new String[]{originalCommentId, commentName, commentContent}); new String[]{originalCommentId, commentName, commentContent});
} }
} }
CommentMgmtService.setCommentThumbnailURL(comment); CommentMgmtService.setCommentThumbnailURL(comment);
...@@ -455,7 +455,7 @@ public final class CommentMgmtService { ...@@ -455,7 +455,7 @@ public final class CommentMgmtService {
final String hashedEmail = MD5.hash(commentEmail.toLowerCase()); final String hashedEmail = MD5.hash(commentEmail.toLowerCase());
String thumbnailURL = "http://secure.gravatar.com/avatar/" + hashedEmail + "?s=60&d=" String thumbnailURL = "http://secure.gravatar.com/avatar/" + hashedEmail + "?s=60&d="
+ Latkes.getStaticServePath() + "/images/default-user-thumbnail.png"; + Latkes.getStaticServePath() + "/images/default-user-thumbnail.png";
final URL gravatarURL = new URL(thumbnailURL); final URL gravatarURL = new URL(thumbnailURL);
......
/* /*
* Copyright (c) 2009, 2010, 2011, 2012, B3log Team * Copyright (c) 2009, 2010, 2011, 2012, B3log Team
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/** /**
* index for admin * 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.0, Aug 30, 2012 * @version 1.0.2.0, Aug 30, 2012
*/ */
var Admin = function () { var Admin = function () {
this.register = {}; this.register = {};
// 工具栏下的工具 // 工具栏下的工具
this.tools = ['#page-list', '#file-list', '#link-list', '#preference', this.tools = ['#page-list', '#file-list', '#link-list', '#preference',
'#user-list', '#plugin-list', '#others']; '#user-list', '#plugin-list', '#others'];
// 多用户时,一般用户不能使用的功能 // 多用户时,一般用户不能使用的功能
this.adTools = ['link-list', 'preference', 'file-list', 'page-list', this.adTools = ['link-list', 'preference', 'file-list', 'page-list',
'user-list', 'plugin-list', 'others']; 'user-list', 'plugin-list', 'others'];
}; };
$.extend(Admin.prototype, { $.extend(Admin.prototype, {
/* /*
* 登出 * 登出
*/ */
logout: function () { logout: function () {
window.location.href = latkeConfig.servePath + "/logout?goto=" + latkeConfig.servePath; window.location.href = latkeConfig.servePath + "/logout?goto=" + latkeConfig.servePath;
}, },
/* /*
* 根据当前页数设置 hash * 根据当前页数设置 hash
* @currentPage {string} 当前页 * @currentPage {string} 当前页
*/ */
setHashByPage: function (currentPage) { setHashByPage: function (currentPage) {
var hash = window.location.hash, var hash = window.location.hash,
hashList = hash.split("/"); hashList = hash.split("/");
if (/^\d*$/.test(hashList[hashList.length - 1])) { if (/^\d*$/.test(hashList[hashList.length - 1])) {
hashList[hashList.length - 1] = currentPage; hashList[hashList.length - 1] = currentPage;
} else { } else {
hashList.push(currentPage); hashList.push(currentPage);
} }
window.location.hash = hashList.join("/"); window.location.hash = hashList.join("/");
}, },
/* /*
* 设置某个 tab 被选择 * 设置某个 tab 被选择
* @id tab id * @id tab id
*/ */
selectTab: function (id) { selectTab: function (id) {
window.location.hash = "#" + id; window.location.hash = "#" + id;
}, },
/* /*
* 根据当前 hash 解析出当前页数及 hash 数组。 * 根据当前 hash 解析出当前页数及 hash 数组。
*/ */
analyseHash: function () { analyseHash: function () {
var hash = window.location.hash; var hash = window.location.hash;
var tag = hash.substr(1, hash.length - 1); var tag = hash.substr(1, hash.length - 1);
var tagList = tag.split("/"); var tagList = tag.split("/");
var tags = {}; var tags = {};
tags.page = 1, tags.page = 1,
tags.hashList = []; tags.hashList = [];
for (var i = 0; i < tagList.length; i++) { for (var i = 0; i < tagList.length; i++) {
if (i === tagList.length - 1 && (/^\d+$/.test(tagList[i]))) { if (i === tagList.length - 1 && (/^\d+$/.test(tagList[i]))) {
tags.page = tagList[i]; tags.page = tagList[i];
} else { } else {
tags.hashList.push(tagList[i]); tags.hashList.push(tagList[i]);
} }
} }
return tags; return tags;
}, },
/* /*
* 根据当前 hash 设置当前 tab * 根据当前 hash 设置当前 tab
*/ */
setCurByHash: function () { setCurByHash: function () {
var tags = admin.analyseHash(); var tags = admin.analyseHash();
var tab = tags.hashList[1], var tab = tags.hashList[1],
subTab = tags.hashList[2]; subTab = tags.hashList[2];
if (tags.hashList.length === 1) { if (tags.hashList.length === 1) {
tab = tags.hashList[0]; tab = tags.hashList[0];
} }
if (tab === "") { if (tab === "") {
return; return;
} }
// 离开编辑器时进行提示 // 离开编辑器时进行提示
try { try {
// 除更新、发布、取消发布文章,编辑器中无内容外,离开编辑器需进行提示。 // 除更新、发布、取消发布文章,编辑器中无内容外,离开编辑器需进行提示。
if (tab !== "article" && admin.article.isConfirm && if (tab !== "article" && admin.article.isConfirm &&
admin.editorArticle.getContent().replace(/\s/g, '') !== "") { admin.editorArticle.getContent().replace(/\s/g, '') !== "") {
if (!confirm(Label.editorLeaveLabel)) { if (!confirm(Label.editorLeaveLabel)) {
window.location.hash = "#article/article"; window.location.hash = "#article/article";
return; return;
} }
} }
// 不离开编辑器,hash 需变为 "#article/article",此时不需要做任何处理。 // 不离开编辑器,hash 需变为 "#article/article",此时不需要做任何处理。
if (tab === "article" && admin.article.isConfirm && if (tab === "article" && admin.article.isConfirm &&
admin.editorArticle.getContent().replace(/\s/g, '') !== "") { admin.editorArticle.getContent().replace(/\s/g, '') !== "") {
return; return;
} }
} catch (e) { } catch (e) {
var $articleContent = $('#articleContent'); var $articleContent = $('#articleContent');
if ($articleContent.length > 0) { if ($articleContent.length > 0) {
if (tab !== "article" && admin.article.isConfirm && if (tab !== "article" && admin.article.isConfirm &&
$articleContent.val().replace(/\s/g, '') !== "") { $articleContent.val().replace(/\s/g, '') !== "") {
if (!confirm(Label.editorLeaveLabel)) { if (!confirm(Label.editorLeaveLabel)) {
window.location.hash = "#article/article"; window.location.hash = "#article/article";
return; return;
} }
} }
// 不离开编辑器,hash 需变为 "#article/article",此时不需要做任何处理。 // 不离开编辑器,hash 需变为 "#article/article",此时不需要做任何处理。
if (tab === "article" && admin.article.isConfirm && if (tab === "article" && admin.article.isConfirm &&
$articleContent.val().replace(/\s/g, '') !== "") { $articleContent.val().replace(/\s/g, '') !== "") {
return; return;
} }
} }
} }
// clear article // clear article
if (tab !== "article" && admin.editorArticle.setContent) { if (tab !== "article" && admin.editorArticle.setContent) {
admin.article.clear(); admin.article.clear();
} }
admin.article.isConfirm = true; admin.article.isConfirm = true;
$("#tabs").tabs("setCurrent", tab); $("#tabs").tabs("setCurrent", tab);
$("#loadMsg").text(Label.loadingLabel); $("#loadMsg").text(Label.loadingLabel);
if ($("#tabsPanel_" + tab).length === 1) { if ($("#tabsPanel_" + tab).length === 1) {
if ($("#tabsPanel_" + tab).html().replace(/\s/g, "") === "") { if ($("#tabsPanel_" + tab).html().replace(/\s/g, "") === "") {
// 还未加载 HTML // 还未加载 HTML
$("#tabsPanel_" + tab).load("admin-" + tab + ".do", function () { $("#tabsPanel_" + tab).load("admin-" + tab + ".do", function () {
// 页面加载完后,回调初始函数 // 页面加载完后,回调初始函数
if (tab === "article" && admin.article.status.id) { if (tab === "article" && admin.article.status.id) {
// 当文章页面编辑器未初始化时,调用更新文章需先初始化编辑器 // 当文章页面编辑器未初始化时,调用更新文章需先初始化编辑器
admin.register[tab].init.call(admin.register[tab].obj, admin.article.getAndSet); admin.register[tab].init.call(admin.register[tab].obj, admin.article.getAndSet);
} else { } else {
admin.register[tab].init.call(admin.register[tab].obj, tags.page); admin.register[tab].init.call(admin.register[tab].obj, tags.page);
} }
// 页面包含子 tab,需根据 hash 定位到相应的 tab // 页面包含子 tab,需根据 hash 定位到相应的 tab
if (subTab) { if (subTab) {
$("#tab" + tab.substring(0, 1).toUpperCase() + tab.substring(1)). $("#tab" + tab.substring(0, 1).toUpperCase() + tab.substring(1)).
tabs("setCurrent", subTab); tabs("setCurrent", subTab);
} }
// 根据 hash 调用现有的插件函数 // 根据 hash 调用现有的插件函数
admin.plugin.setCurByHash(tags); admin.plugin.setCurByHash(tags);
}); });
} else { } else {
if (tab === "article" && admin.article.status.id) { if (tab === "article" && admin.article.status.id) {
admin.article.getAndSet(); admin.article.getAndSet();
} }
// 已加载过 HTML,只需调用刷新函数 // 已加载过 HTML,只需调用刷新函数
if (admin.register[tab] && admin.register[tab].refresh) { if (admin.register[tab] && admin.register[tab].refresh) {
admin.register[tab].refresh.call(admin.register[tab].obj, tags.page); admin.register[tab].refresh.call(admin.register[tab].obj, tags.page);
} }
// 页面包含子 tab,需根据 hash 定位到相应的 tab // 页面包含子 tab,需根据 hash 定位到相应的 tab
if (subTab) { if (subTab) {
$("#tab" + tab.substring(0, 1).toUpperCase() + tab.substring(1)). $("#tab" + tab.substring(0, 1).toUpperCase() + tab.substring(1)).
tabs("setCurrent", subTab); tabs("setCurrent", subTab);
} }
// 根据 hash 调用现有的插件函数 // 根据 hash 调用现有的插件函数
admin.plugin.setCurByHash(tags); admin.plugin.setCurByHash(tags);
} }
} else { } else {
$("#tipMsg").text("Error: No tab! " + Label.reportIssueLabel); $("#tipMsg").text("Error: No tab! " + Label.reportIssueLabel);
$("#loadMsg").text(""); $("#loadMsg").text("");
} }
}, },
/* /*
* 初始化整个后台 * 初始化整个后台
*/ */
init: function () { init: function () {
//window.onerror = Util.error; //window.onerror = Util.error;
Util.killIE(); Util.killIE();
$("#loadMsg").text(Label.loadingLabel); $("#loadMsg").text(Label.loadingLabel);
// 构建 tabs // 构建 tabs
$("#tabs").tabs(); $("#tabs").tabs();
// tipMsg // tipMsg
setInterval(function () { setInterval(function () {
if($("#tipMsg").text() !== "") { if($("#tipMsg").text() !== "") {
setTimeout(function () { setTimeout(function () {
$("#tipMsg").text(""); $("#tipMsg").text("");
}, 7000); }, 7000);
} }
}, 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();
subNav.slideToggle("normal", function () { subNav.slideToggle("normal", function () {
if (this.style.display !== "none") { if (this.style.display !== "none") {
$(it).find(".ico-arrow-down")[0].className = "ico-arrow-up"; $(it).find(".ico-arrow-down")[0].className = "ico-arrow-up";
} else { } else {
$(it).find(".ico-arrow-up")[0].className = "ico-arrow-down"; $(it).find(".ico-arrow-up")[0].className = "ico-arrow-down";
} }
}); });
}, },
/* /*
* 后台及当前页面所需插件初始化完后,对权限进行控制及当前页面属于 tools 时,tools 选项需展开。 * 后台及当前页面所需插件初始化完后,对权限进行控制及当前页面属于 tools 时,tools 选项需展开。
*/ */
inited: function () { inited: function () {
// Removes functions with the current user role // Removes functions with the current user role
if (Label.userRole !== "adminRole") { if (Label.userRole !== "adminRole") {
for (var i = 0; i < this.adTools.length; i++) { for (var i = 0; i < this.adTools.length; i++) {
$("#tabs").tabs("remove", this.adTools[i]); $("#tabs").tabs("remove", this.adTools[i]);
} }
} else { } else {
// 当前 tab 属于 Tools 时,设其展开 // 当前 tab 属于 Tools 时,设其展开
for (var j = 0; j < this.tools.length; j++) { for (var j = 0; j < this.tools.length; j++) {
if ("#" + window.location.hash.split("/")[1] === this.tools[j]) { if ("#" + window.location.hash.split("/")[1] === this.tools[j]) {
$("#tabToolsTitle").click(); $("#tabToolsTitle").click();
break; break;
} }
} }
} }
this.setCurByHash(); this.setCurByHash();
} }
}); });
var admin = new Admin();/* var admin = new Admin();/*
* Copyright (c) 2009, 2010, 2011, 2012, B3log Team * Copyright (c) 2009, 2010, 2011, 2012, B3log Team
* *
......
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