forked from plainblack/Lacuna-Web-Client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildingEntertainment.js
99 lines (87 loc) · 3.2 KB
/
buildingEntertainment.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
YAHOO.namespace("lacuna.buildings");
if (typeof YAHOO.lacuna.buildings.Entertainment == "undefined" || !YAHOO.lacuna.buildings.Entertainment) {
(function(){
var Util = YAHOO.util,
Dom = Util.Dom,
Event = Util.Event,
Lacuna = YAHOO.lacuna,
Game = Lacuna.Game,
Lib = Lacuna.Library;
var Entertainment = function(result){
Entertainment.superclass.constructor.call(this, result);
this.service = Game.Services.Buildings.Entertainment;
this.lotteryAllVotedMessage = "You have voted as many times as you could today. Please check back tomorrow for your next chance!";
};
YAHOO.lang.extend(Entertainment, Lacuna.buildings.Building, {
getChildTabs : function() {
return [this._getLotteryTab()];
},
_getLotteryTab : function() {
var tab = new YAHOO.widget.Tab({ label: "Lottery", content: ['<p id="entertainmentLotteryMessage">Welcome to the Lacuna Lottery! Get entered in the Expanse\'s daily lottery for a chance to win 10 <img src="',Lib.AssetUrl,'ui/s/essentia.png" class="smallEssentia" />! Each link clicked below gives you one extra chance to win. Links will be removed after voting and return tomorrow.</p><div><ul id="entertainmentLotteryList"></ul></div>'].join('')});
tab.subscribe("activeChange", this.LotteryView, this, true);
return tab;
},
LotteryView : function(e) {
if(e.newValue) {
Lacuna.Pulser.Show();
this.service.get_lottery_voting_options({session_id:Game.GetSession(),building_id:this.building.id}, {
success : function(o){
Lacuna.Pulser.Hide();
this.rpcSuccess(o);
this.LotteryPopulate(o.result.options);
},
failure : function(o){
Lacuna.Pulser.Hide();
this.rpcFailure(o);
},
timeout:Game.Timeout,
scope:this
});
}
},
LotteryPopulate : function(options) {
var details = Dom.get("entertainmentLotteryList");
if(details) {
var li = document.createElement("li");
Event.purgeElement(details);
details.innerHTML = "";
Dom.setStyle(details.parentNode,"height","");
Dom.setStyle(details.parentNode,"overflow-y","");
if(options.length == 0) {
li.innerHTML = this.lotteryAllVotedMessage;
details.appendChild(li);
}
else {
for(var i=0; i<options.length; i++) {
var vote = options[i],
nLi = li.cloneNode(false);
nLi.innerHTML = ['<a href="',vote.url,'" target="_new">',vote.name,'</a>'].join('');
Event.on(nLi, "click", this.LotteryVoted, this);
details.appendChild(nLi);
}
//wait for tab to display first
setTimeout(function() {
if(details.parentNode.clientHeight > 300) {
Dom.setStyle(details.parentNode,"height","300px");
Dom.setStyle(details.parentNode,"overflow-y","auto");
}
},10);
}
}
},
LotteryVoted : function(e, oSelf) {
var li = Event.getTarget(e);
if(li) {
Event.removeListener(li, "click");
var ul = li.parentNode;
ul.removeChild(li);
if(ul.children && ul.children.length == 0) {
ul.innerHTML = ['<li>',this.lotteryAllVotedMessage,'</li>'].join('');
}
}
}
});
Lacuna.buildings.Entertainment = Entertainment;
})();
YAHOO.register("Entertainment", YAHOO.lacuna.buildings.Entertainment, {version: "1", build: "0"});
}