forked from plainblack/Lacuna-Web-Client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createSpecies.js
132 lines (124 loc) · 4.6 KB
/
createSpecies.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
128
129
130
131
132
YAHOO.namespace("lacuna");
if (typeof YAHOO.lacuna.CreateSpecies == "undefined" || !YAHOO.lacuna.CreateSpecies) {
(function(){
var Util = YAHOO.util,
Dom = Util.Dom,
Event = Util.Event,
Sel = Util.Selector,
Lacuna = YAHOO.lacuna,
Game = Lacuna.Game,
Lib = Lacuna.Library;
var CreateSpecies = function(Empire) {
this.id = "createSpecies";
this._empire = Empire;
this.createEvent("onCreateSuccessful");
var container = document.createElement("div");
container.id = this.id;
Dom.addClass(container, Lib.Styles.HIDDEN);
container.innerHTML = this._getHtml();
document.body.insertBefore(container, document.body.firstChild);
this.Dialog = new YAHOO.widget.Dialog(this.id, {
constraintoviewport:false,
//fixedcenter:true,
postmethod:"none",
visible:false,
buttons:[ { text:"Found Empire", handler:{fn:this.handleCreate, scope:this}, isDefault:true },
{ text:"Cancel", handler:{fn:this.handleCancel, scope:this} } ],
draggable:true,
effect:Game.GetContainerEffect(),
modal:false,
close:false,
width:"735px",
underlay:false,
zIndex:9999
});
this.Dialog.renderEvent.subscribe(function(){
this.elMessage = Dom.get('speciesMessage');
this.designer = new Lacuna.SpeciesDesigner();
this.designer.render("speciesCreateDesign");
Dom.removeClass(this.id, Lib.Styles.HIDDEN);
}, this, true);
this.Dialog.render();
Game.OverlayManager.register(this.Dialog);
};
CreateSpecies.prototype = {
handleCreate : function() {
this.setMessage("");
var EmpireServ = Game.Services.Empire,
data = this.designer.getSpeciesData();
try {
if ( ! this.designer.validateSpecies(data) ) {
return;
}
}
catch (e) {
this.setMessage(e);
return;
}
delete data.affinity_total;
EmpireServ.update_species({empire_id: this.empireId, params: data}, {
success : function(o) {
YAHOO.log(o, "info", "CreateSpecies");
this._found();
},
failure : function(o){
this.setMessage(o.error.message);
return true;
},
scope:this
});
},
handleCancel : function() {
this.hide();
this._empire.handleCancel();
},
_found : function() {
Lacuna.Pulser.Show();
var EmpireServ = Game.Services.Empire;
EmpireServ.found({empire_id: this.empireId, api_key:Lib.ApiKey}, {
success : function(o) {
YAHOO.log(o, "info", "CreateSpecies._found.success");
Lacuna.Pulser.Hide();
this.hide(); //hide species
this.fireEvent("onCreateSuccessful", o);
},
failure : function(o) {
this.setMessage(o.error.message);
return true;
},
scope:this
});
},
_getHtml : function() {
return [
' <div class="hd">Create Species</div>',
' <div class="bd">',
' <form name="speciesForm">',
' <div id="speciesCreateDesign"></div>',
' <div id="speciesMessage" class="hidden"></div>',
' </form>',
' </div>',
' <div class="ft"></div>'
].join('');
},
setMessage : function(str) {
Dom.replaceClass(this.elMessage, Lib.Styles.HIDDEN, Lib.Styles.ALERT);
this.elMessage.innerHTML = str;
},
show : function(empire) {
this.empireId = empire;
Game.OverlayManager.hideAll();
this.Dialog.show();
this.Dialog.center();
},
hide : function() {
Dom.replaceClass(this.elMessage, Lib.Styles.ALERT, Lib.Styles.HIDDEN);
this.Dialog.hide();
}
};
YAHOO.lang.augmentProto(CreateSpecies, Util.EventProvider);
Lacuna.CreateSpecies = CreateSpecies;
})();
YAHOO.register("createSpecies", YAHOO.lacuna.CreateSpecies, {version: "1", build: "0"});
}
// vim: noet:ts=4:sw=4