forked from plainblack/Lacuna-Web-Client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildingNetwork19.js
127 lines (107 loc) · 5.32 KB
/
buildingNetwork19.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
YAHOO.namespace("lacuna.buildings");
if (typeof YAHOO.lacuna.buildings.Network19 == "undefined" || !YAHOO.lacuna.buildings.Network19) {
(function(){
var Lang = YAHOO.lang,
Util = YAHOO.util,
Dom = Util.Dom,
Event = Util.Event,
Sel = Util.Selector,
Lacuna = YAHOO.lacuna,
Game = Lacuna.Game,
Lib = Lacuna.Library;
var Network19 = function(result){
Network19.superclass.constructor.call(this, result);
this.service = Game.Services.Buildings.Network19;
};
Lang.extend(Network19, Lacuna.buildings.Building, {
getChildTabs : function() {
return [this._getCoverageTab()];
},
_getCoverageTab : function() {
this.coverageTab = new YAHOO.widget.Tab({ label: "Coverage", content: [
'<div id="newsCoverageContainer">',
' <span id="newsCoverageText">',this.result.restrict_coverage == "1" ? 'Coverage is current restricted' : 'News is flowing freely', '</span>',
' : <button id="newsCoverage" type="button">',(this.result.restrict_coverage == "1" ? 'Open Coverage' : 'Restrict Coverage'),'</button>',
'</div>',
'<div class="newsFeedContainer">',
' <ul id="newsFeed">',
' </ul>',
'</div>',
'<div class="newsRssLinksContainer">',
' <ul id="newsRssLinks" class="clearafter">',
' </ul>',
'</div>'
].join('')});
this.coverageTab.subscribe("activeChange", this.NewsGet, this, true);
Event.on("newsCoverage", "click", this.NewsCoverage, this, true);
return this.coverageTab;
},
NewsCoverage : function(e) {
var target = Event.getTarget(e),
isRestrict = 1;
target.disabled = true;
if(target.innerHTML == "Open Coverage") {
isRestrict = 0;
}
Lacuna.Pulser.Show();
this.service.restrict_coverage({session_id:Game.GetSession(),building_id:this.result.building.id,onoff:isRestrict}, {
success : function(o){
YAHOO.log(o, "info", "Network19.NewsCoverage.restrict_coverage.success");
Lacuna.Pulser.Hide();
this.rpcSuccess(o);
Dom.get("newsCoverageText").innerHTML = isRestrict ? 'Coverage is currently restricted' : 'News is flowing freely';
target.innerHTML = isRestrict ? 'Open Coverage' : 'Restrict Coverage';
target.disabled = false;
},
failure : function(o){
target.disabled = false;
},
scope:this
});
},
NewsGet : function() {
Lacuna.Pulser.Show();
this.service.view_news({session_id:Game.GetSession(),building_id:this.building.id}, {
success : function(o){
YAHOO.log(o, "info", "Network19.NewsGet.success");
Lacuna.Pulser.Hide();
this.rpcSuccess(o);
var news = o.result.news,
newsFeed = Dom.get("newsFeed");
if(newsFeed) {
var feedFrag = document.createDocumentFragment(),
rss = o.result.feeds,
newsRssLinks = Dom.get("newsRssLinks"),
rssFrag = document.createDocumentFragment(),
li = document.createElement("li");
newsFeed.innerHTML = "";
newsRssLinks.innerHTML = "";
for(var i=0; i<news.length; i++) {
var ni = news[i],
nLi = li.cloneNode(false);
Dom.addClass(nLi, "newsHeadline");
nLi.innerHTML = [Lib.formatServerDateShort(ni.date), ": ", ni.headline].join('');
feedFrag.appendChild(nLi);
}
newsFeed.appendChild(feedFrag);
for(var key in rss) {
if(rss.hasOwnProperty(key)){
var link = rss[key],
rssLi = li.cloneNode(false);
Dom.addClass(rssLi, "newsRssLink");
rssLi.innerHTML = [key, '<a href="', link, '" target="_blank"><img src="', Lib.AssetUrl, 'ui/rss.png" alt="rss" style="margin-left:1px" /></a>'].join('');
rssFrag.appendChild(rssLi);
}
}
newsRssLinks.appendChild(rssFrag);
}
},
scope:this
});
}
});
YAHOO.lacuna.buildings.Network19 = Network19;
})();
YAHOO.register("network19", YAHOO.lacuna.buildings.Network19, {version: "1", build: "0"});
}
// vim: noet:ts=4:sw=4