Commit a00f0951 authored by Liang Ding's avatar Liang Ding

#216

parent e70f4bde
...@@ -18,6 +18,7 @@ package org.b3log.solo.plugin.broadcast; ...@@ -18,6 +18,7 @@ package org.b3log.solo.plugin.broadcast;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.concurrent.Future;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
...@@ -30,6 +31,7 @@ import org.b3log.latke.servlet.annotation.RequestProcessing; ...@@ -30,6 +31,7 @@ import org.b3log.latke.servlet.annotation.RequestProcessing;
import org.b3log.latke.servlet.annotation.RequestProcessor; import org.b3log.latke.servlet.annotation.RequestProcessor;
import org.b3log.latke.servlet.renderer.JSONRenderer; import org.b3log.latke.servlet.renderer.JSONRenderer;
import org.b3log.latke.urlfetch.HTTPRequest; import org.b3log.latke.urlfetch.HTTPRequest;
import org.b3log.latke.urlfetch.HTTPResponse;
import org.b3log.latke.urlfetch.URLFetchService; import org.b3log.latke.urlfetch.URLFetchService;
import org.b3log.latke.urlfetch.URLFetchServiceFactory; import org.b3log.latke.urlfetch.URLFetchServiceFactory;
import org.b3log.latke.util.Requests; import org.b3log.latke.util.Requests;
...@@ -49,7 +51,7 @@ import org.json.JSONObject; ...@@ -49,7 +51,7 @@ import org.json.JSONObject;
* Broadcast chance processor. * Broadcast chance processor.
* *
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a> * @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.7, May 16, 2012 * @version 1.0.0.8, Apr 24, 2013
* @since 0.6.0 * @since 0.6.0
*/ */
@RequestProcessor @RequestProcessor
...@@ -246,7 +248,7 @@ public final class ChanceProcessor { ...@@ -246,7 +248,7 @@ public final class ChanceProcessor {
* "broadcast": { * "broadcast": {
* "title": "", * "title": "",
* "content": "", * "content": "",
* "link": "" * "link": "" // optional
* } * }
* } * }
* </pre> * </pre>
...@@ -293,16 +295,28 @@ public final class ChanceProcessor { ...@@ -293,16 +295,28 @@ public final class ChanceProcessor {
broadcastRequest.put("clientVersion", clientVersion); broadcastRequest.put("clientVersion", clientVersion);
broadcastRequest.put("clientName", clientName); broadcastRequest.put("clientName", clientName);
broadcastRequest.put("clientHost", blogHost); broadcastRequest.put("clientHost", blogHost);
final HTTPRequest httpRequest = new HTTPRequest(); final HTTPRequest httpRequest = new HTTPRequest();
httpRequest.setURL(ADD_BROADCAST_URL); httpRequest.setURL(ADD_BROADCAST_URL);
httpRequest.setRequestMethod(HTTPRequestMethod.POST); httpRequest.setRequestMethod(HTTPRequestMethod.POST);
httpRequest.setPayload(broadcastRequest.toString().getBytes("UTF-8")); httpRequest.setPayload(broadcastRequest.toString().getBytes("UTF-8"));
urlFetchService.fetchAsync(httpRequest); @SuppressWarnings("unchecked")
final Future<HTTPResponse> future = (Future<HTTPResponse>) urlFetchService.fetchAsync(httpRequest);
final HTTPResponse result = future.get();
ret.put(Keys.STATUS_CODE, true); if (HttpServletResponse.SC_OK == result.getResponseCode()) {
ret.put(Keys.STATUS_CODE, true);
optionMgmtService.removeOption(Option.ID_C_BROADCAST_CHANCE_EXPIRATION_TIME);
LOGGER.info("Submits broadcast successfully");
return;
}
ret.put(Keys.STATUS_CODE, false);
} catch (final Exception e) { } catch (final Exception e) {
LOGGER.log(Level.SEVERE, "Submits broadcast failed", e); LOGGER.log(Level.SEVERE, "Submits broadcast failed", e);
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
plugins.b3logBroadcast = { plugins.b3logBroadcast = {
init: function() { init: function() {
$("#loadMsg").text("${loadingLabel}"); $("#loadMsg").text("${loadingLabel}");
// dialog // dialog
$("#b3logBroadcastDialog").dialog({ $("#b3logBroadcastDialog").dialog({
width: 700, width: 700,
...@@ -96,33 +96,32 @@ ...@@ -96,33 +96,32 @@
url: "http://symphony.b3log.org/apis/broadcasts", url: "http://symphony.b3log.org/apis/broadcasts",
dataType: "jsonp", dataType: "jsonp",
jsonp: "callback", jsonp: "callback",
beforeSend: function () { beforeSend: function() {
$("#b3logBroadcastList").css("background", $("#b3logBroadcastList").css("background",
"url(${staticServePath}/images/loader.gif) no-repeat scroll center center transparent"); "url(${staticServePath}/images/loader.gif) no-repeat scroll center center transparent");
}, },
error: function() { error: function() {
$("#b3logBroadcastList").html("Loading Symphony broadcasts failed :-(").css("background", "none"); $("#b3logBroadcastList").html("Loading Symphony broadcasts failed :-(").css("background", "none");
}, },
success: function(result) { success: function(result) {
if (result.sc) { var articles = result.articles;
var articles = result.articles;
if (0 === articles.length) {
return;
}
var listHTML = "<ul>"; if (0 === articles.length) {
for (var i = 0; i < articles.length; i++) { return;
var article = articles[i]; }
var articleLiHtml = "<li>"
+ "<a target='_blank' href='" + article.articlePermalink + "'>"
+ article.articleTitle + "</a>&nbsp; <span class='date'>" + $.bowknot.getDate(article.articleCreateTime, 1);
+"</span></li>"
listHTML += articleLiHtml
}
listHTML += "</ul>";
$("#b3logBroadcastList").html(listHTML).css("background", "none"); var listHTML = "<ul>";
for (var i = 0; i < articles.length; i++) {
var article = articles[i];
var articleLiHtml = "<li>"
+ "<a target='_blank' href='" + article.articlePermalink + "'>"
+ article.articleTitle + "</a>&nbsp; <span class='date'>" + $.bowknot.getDate(article.articleCreateTime, 1);
+"</span></li>"
listHTML += articleLiHtml
} }
listHTML += "</ul>";
$("#b3logBroadcastList").html(listHTML).css("background", "none");
}, },
complete: function(XMLHttpRequest, textStatus) { complete: function(XMLHttpRequest, textStatus) {
$("#loadMsg").text(""); $("#loadMsg").text("");
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
# #
rendererId=admin-main.ftl rendererId=admin-main.ftl
author=<a href="http://88250.b3log.org">88250</a> & <a href="http://vanessa.b3log.org">Vanessa</a> author=<a href="http://88250.b3log.org">88250</a> & <a href="http://vanessa.b3log.org">Vanessa</a>
name=b3log broadcast name=B3log Broadcast
version=0.0.1 version=0.0.1
types=ADMIN types=ADMIN
......
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