96 /* Point of entry */ |
96 /* Point of entry */ |
97 |
97 |
98 Rkns.Renkan = function(_opts) { |
98 Rkns.Renkan = function(_opts) { |
99 var _this = this; |
99 var _this = this; |
100 |
100 |
101 if (typeof _opts.language !== "string" || typeof Rkns.i18n[_opts.language] == "undefined") { |
101 this.options = _.defaults(_opts, Rkns.defaults); |
102 _opts.language = (navigator.language || navigator.userLanguage || "en"); |
102 |
103 } |
103 Rkns._(this.options.property_files).each(function(f) { |
104 if (typeof _opts.container !== "string") { |
104 Rkns.$.getJSON(f, function(data) { |
105 _opts.container = "renkan"; |
105 _this.options.properties = _this.options.properties.concat(data); |
106 } |
106 }); |
107 if (typeof _opts.search !== "object" || !_opts.search) { |
107 }); |
108 _opts.search = []; |
108 |
109 } |
109 this.read_only = this.options.read_only || !this.options.editor_mode; |
110 if (typeof _opts.bins !== "object" || !_opts.bins) { |
110 |
111 _opts.bins = []; |
|
112 } |
|
113 if (typeof _opts.static_url !== "string") { |
|
114 _opts.static_url = ""; |
|
115 } |
|
116 if (typeof _opts.show_bins !== "boolean") { |
|
117 _opts.show_bins = !!_opts.search.length || !!_opts.bins.length; |
|
118 } |
|
119 if (typeof _opts.properties !== "object") { |
|
120 _opts.properties = []; |
|
121 } |
|
122 if (typeof _opts.property_files === "object") { |
|
123 Rkns._(_opts.property_files).each(function(f) { |
|
124 Rkns.$.getJSON(f, function(data) { |
|
125 _this.properties = _this.properties.concat(data); |
|
126 }); |
|
127 }); |
|
128 } |
|
129 if (typeof _opts.clip_images === "undefined") { |
|
130 _opts.clip_images = true; |
|
131 } |
|
132 this.project = new Rkns.Models.Project(); |
111 this.project = new Rkns.Models.Project(); |
133 this.language = _opts.language; |
|
134 this.static_url = _opts.static_url; |
|
135 this.show_bins = _opts.show_bins; |
|
136 this.properties = _opts.properties; |
|
137 this.clip_images = _opts.clip_images; |
|
138 this.read_only = _opts.read_only || false; |
|
139 this.snapshot_mode = _opts.snapshot_mode || false; |
|
140 |
112 |
141 this.translate = function(_text) { |
113 this.translate = function(_text) { |
142 return (Rkns.i18n[_opts.language] || Rkns.i18n[_opts.language.substr(0,2)] || {})[_text] || _text; |
114 return (Rkns.i18n[_this.options.language] || Rkns.i18n[_this.options.language.substr(0,2)] || {})[_text] || _text; |
143 } |
115 } |
144 if (typeof _opts.user_id !== "undefined") { |
116 if (typeof this.options.user_id !== "undefined") { |
145 this.current_user = _opts.user_id; |
117 this.current_user = this.options.user_id; |
146 } |
118 } |
147 this.$ = Rkns.$("#" + _opts.container); |
119 this.$ = Rkns.$("#" + this.options.container); |
148 this.$ |
120 this.$ |
149 .addClass("Rk-Main") |
121 .addClass("Rk-Main") |
150 .html(this.template(this)); |
122 .html(this.template(this)); |
151 this.renderer = new Rkns.Renderer.Scene(this); |
123 this.renderer = new Rkns.Renderer.Scene(this); |
152 this.tabs = []; |
124 this.tabs = []; |
153 this.search_engines = []; |
125 this.search_engines = []; |
154 |
126 |
155 this.current_user_list = new Rkns.Models.UsersList(); |
127 this.current_user_list = new Rkns.Models.UsersList(); |
156 |
128 |
157 if (!_opts.search.length) { |
129 if (!this.options.search.length) { |
158 this.$.find(".Rk-Web-Search-Form").detach(); |
130 this.$.find(".Rk-Web-Search-Form").detach(); |
159 } else { |
131 } else { |
160 var _tmpl = Rkns._.template('<li class="<%= className %>" data-key="<%= key %>"><%= title %></li>'), |
132 var _tmpl = Rkns._.template('<li class="<%= className %>" data-key="<%= key %>"><%= title %></li>'), |
161 _select = this.$.find(".Rk-Search-List"), |
133 _select = this.$.find(".Rk-Search-List"), |
162 _input = this.$.find(".Rk-Web-Search-Input") |
134 _input = this.$.find(".Rk-Web-Search-Input") |
163 _form = this.$.find(".Rk-Web-Search-Form"); |
135 _form = this.$.find(".Rk-Web-Search-Form"); |
164 Rkns._(_opts.search).each(function(_search, _key) { |
136 Rkns._(this.options.search).each(function(_search, _key) { |
165 if (Rkns[_search.type] && Rkns[_search.type].Search) { |
137 if (Rkns[_search.type] && Rkns[_search.type].Search) { |
166 _this.search_engines.push(new Rkns[_search.type].Search(_this, _search)); |
138 _this.search_engines.push(new Rkns[_search.type].Search(_this, _search)); |
167 } |
139 } |
168 }); |
140 }); |
169 _select.html( |
141 _select.html( |
249 return false |
221 return false |
250 }); |
222 }); |
251 } |
223 } |
252 |
224 |
253 Rkns.Renkan.prototype.template = Rkns._.template( |
225 Rkns.Renkan.prototype.template = Rkns._.template( |
254 '<% if (show_bins) { %><div class="Rk-Bins"><div class="Rk-Bins-Head"><h2 class="Rk-Bins-Title"><%- translate("Select contents:")%></h2>' |
226 '<% if (options.show_bins) { %><div class="Rk-Bins"><div class="Rk-Bins-Head"><h2 class="Rk-Bins-Title"><%- translate("Select contents:")%></h2>' |
255 + '<form class="Rk-Web-Search-Form Rk-Search-Form"><input class="Rk-Web-Search-Input Rk-Search-Input" type="search" placeholder="<%- translate("Search the Web") %>" />' |
227 + '<form class="Rk-Web-Search-Form Rk-Search-Form"><input class="Rk-Web-Search-Input Rk-Search-Input" type="search" placeholder="<%- translate("Search the Web") %>" />' |
256 + '<div class="Rk-Search-Select"><div class="Rk-Search-Current"></div><ul class="Rk-Search-List"></ul></div>' |
228 + '<div class="Rk-Search-Select"><div class="Rk-Search-Current"></div><ul class="Rk-Search-List"></ul></div>' |
257 + '<input type="submit" value="" class="Rk-Web-Search-Submit Rk-Search-Submit" /></form>' |
229 + '<input type="submit" value="" class="Rk-Web-Search-Submit Rk-Search-Submit" /></form>' |
258 + '<form class="Rk-Bins-Search-Form Rk-Search-Form"><input class="Rk-Bins-Search-Input Rk-Search-Input" type="search" placeholder="<%- translate("Search in Bins") %>" />' |
230 + '<form class="Rk-Bins-Search-Form Rk-Search-Form"><input class="Rk-Bins-Search-Input Rk-Search-Input" type="search" placeholder="<%- translate("Search in Bins") %>" />' |
259 + '<input type="submit" value="" class="Rk-Bins-Search-Submit Rk-Search-Submit" /></form></div>' |
231 + '<input type="submit" value="" class="Rk-Bins-Search-Submit Rk-Search-Submit" /></form></div>' |
260 + '<ul class="Rk-Bin-List"></ul></div><% } %><div class="Rk-Render Rk-Render-<% if (show_bins) { %>Panel<% } else { %>Full<% } %>"></div>' |
232 + '<ul class="Rk-Bin-List"></ul></div><% } %><div class="Rk-Render Rk-Render-<% if (options.show_bins) { %>Panel<% } else { %>Full<% } %>"></div>' |
261 ); |
233 ); |
262 |
234 |
263 Rkns.Renkan.prototype.onStatusChange = function() { |
235 Rkns.Renkan.prototype.onStatusChange = function() { |
264 this.renderer.onStatusChange(); |
236 this.renderer.onStatusChange(); |
265 } |
237 } |