Commit a00f0951 authored by Liang Ding's avatar Liang Ding

#216

parent e70f4bde
......@@ -18,6 +18,7 @@ package org.b3log.solo.plugin.broadcast;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.Future;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest;
......@@ -30,6 +31,7 @@ import org.b3log.latke.servlet.annotation.RequestProcessing;
import org.b3log.latke.servlet.annotation.RequestProcessor;
import org.b3log.latke.servlet.renderer.JSONRenderer;
import org.b3log.latke.urlfetch.HTTPRequest;
import org.b3log.latke.urlfetch.HTTPResponse;
import org.b3log.latke.urlfetch.URLFetchService;
import org.b3log.latke.urlfetch.URLFetchServiceFactory;
import org.b3log.latke.util.Requests;
......@@ -49,7 +51,7 @@ import org.json.JSONObject;
* Broadcast chance processor.
*
* @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
*/
@RequestProcessor
......@@ -246,7 +248,7 @@ public final class ChanceProcessor {
* "broadcast": {
* "title": "",
* "content": "",
* "link": ""
* "link": "" // optional
* }
* }
* </pre>
......@@ -293,16 +295,28 @@ public final class ChanceProcessor {
broadcastRequest.put("clientVersion", clientVersion);
broadcastRequest.put("clientName", clientName);
broadcastRequest.put("clientHost", blogHost);
final HTTPRequest httpRequest = new HTTPRequest();
httpRequest.setURL(ADD_BROADCAST_URL);
httpRequest.setRequestMethod(HTTPRequestMethod.POST);
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) {
LOGGER.log(Level.SEVERE, "Submits broadcast failed", e);
......
......@@ -33,7 +33,7 @@
plugins.b3logBroadcast = {
init: function() {
$("#loadMsg").text("${loadingLabel}");
// dialog
$("#b3logBroadcastDialog").dialog({
width: 700,
......@@ -96,33 +96,32 @@
url: "http://symphony.b3log.org/apis/broadcasts",
dataType: "jsonp",
jsonp: "callback",
beforeSend: function () {
beforeSend: function() {
$("#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() {
$("#b3logBroadcastList").html("Loading Symphony broadcasts failed :-(").css("background", "none");
},
success: function(result) {
if (result.sc) {
var articles = result.articles;
if (0 === articles.length) {
return;
}
var articles = result.articles;
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>";
if (0 === articles.length) {
return;
}
$("#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) {
$("#loadMsg").text("");
......
......@@ -21,7 +21,7 @@
#
rendererId=admin-main.ftl
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
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