"use strict";
const EXPORTED_SYMBOLS = ["core", "resources"];
const {classes: Cc, interfaces: Ci, results: Cr, utils: Cu} = Components;
const resources = {
browser: {
styles: ["/native/fx/bindings.css"]}};
const WIDGET_NAME = "http://bar.yandex.ru/packages/yandexbar#money";
const core = {
init: function MoneyWidget_init(api) {
this._api = api;
this._logger = api.logger;
this._loadModules();
}
,
finalize: function MoneyWidget_finalize() {
delete this.utils;
delete this._api;
delete this._logger;
delete this.__stringBundle;
}
,
buildWidget: function MoneyWidget_buildWidget(WIID, item) {
item.setAttribute("yb-native-widget-name",WIDGET_NAME);
item.setAttribute("yb-native-widget-wiid",WIID);
item.module = this;
}
,
destroyWidget: function MoneyWidget_destroyWidget(WIID, item, context) {
item.removeAttribute("yb-native-widget-name");
item.removeAttribute("yb-native-widget-wiid");
}
,
get API() {
return this._api;
}
,
__stringBundle: null,
get _stringBundle() {
return this.__stringBundle || (this.__stringBundle = this._api.Localization.createStringBundle("/native/fx/money.properties"));
}
,
onButtonClick: function MoneyWidget_onButtonClick(event, widget) {
if (this.yauth.authorized)
{
this.gotoHome(event);
}
 else
{
let dialogParams = {
name: "money",
title: widget.title};
this.yauth.openAuthDialog(event,dialogParams,false,(function () {
this.gotoHome(event);
}
).bind(this));
}

}
,
counterServiceID: 45,
counterXpathExpr: "number(/s/c/money/@v)",
refreshData: function MoneyWidget_refreshData(event, callback) {
this.counters.forceUpdate(this.counterServiceID,callback);
}
,
gotoHome: function MoneyWidget_gotoHome(event) {
this._navToMoneyPage("",this._STAT_CODES.GOTO_HOME,event);
}
,
gotoShop: function MoneyWidget_gotoShop(event) {
this._navToMoneyPage("shops.xml",this._STAT_CODES.GOTO_SHOP,event);
}
,
gotoPrepay: function MoneyWidget_gotoPrepay(event) {
this._navToMoneyPage("prepaid.xml",this._STAT_CODES.GOTO_PREPAY,event);
}
,
_STAT_CODES: {
GOTO_HOME: 1500,
GOTO_SHOP: 1520,
GOTO_PREPAY: 1510},
_MODULES: {
utils: "utils.jsm",
counters: "counters.jsm",
yauth: "yauth.jsm"},
_getMoneyURL: function MoneyWidget__getMoneyURL() {
return this.utils.tryCreateFixupURI(this._stringBundle.get("MoneyHost")).spec;
}
,
_loadModules: function MoneyWidget__loadModules() {
var shAPI = this._api.shareableAPI;
for each(let [moduleName, moduleFileName] in Iterator(this._MODULES)) {
Cu.import(this._api.Package.resolvePath("/native/fx/modules/" + moduleFileName),this);
let module = this[moduleName];
if (typeof module.init == "function")
module.init(shAPI);
}

}
,
_navToMoneyPage: function MoneyWidget__navToMoneyPage(page, statAction, origEvent) {
var moneyURL = this._getMoneyURL() + (page ? "/" + page : "");
if (statAction)
this.API.Statistics.logShortAction(statAction);
this.API.Controls.navigateBrowser({
url: moneyURL,
eventInfo: origEvent});
}
};
