"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#fotki";
const core = {
init: function FotkiWidget_init(api) {
this._api = api;
this._logger = api.logger;
this._loadModules();
}
,
finalize: function FotkiWidget_finalize() {
delete this.utils;
delete this._api;
delete this._logger;
delete this.__stringBundle;
}
,
buildWidget: function FotkiWidget_buildWidget(WIID, item) {
item.setAttribute("yb-native-widget-name",WIDGET_NAME);
item.setAttribute("yb-native-widget-wiid",WIID);
item.module = this;
}
,
destroyWidget: function FotkiWidget_destroyWidget(WIID, item, context) {
try {
if (typeof item.fotkiDestroy == "function")
item.fotkiDestroy();
}
 finally {
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/fotki.properties"));
}
,
onButtonClick: function FotkiWidget_onButtonClick(event, widget) {
this.API.logger.debug("widget " + widget);
if (this.yauth.authorized)
{
this.gotoFavAuth(event);
}
 else
{
let dialogParams = {
name: "fotki",
title: widget.title};
this.yauth.openAuthDialog(event,dialogParams,false,(function () {
this.gotoFavAuth(event);
}
).bind(this));
}

}
,
counterServiceID: 46,
counterXpathExpr: "number(/s/c/fotki/@v)",
refreshData: function FotkiWidget_refreshData(event, callback) {
this.counters.forceUpdate(this.counterServiceID,callback);
}
,
gotoFavAuth: function FotkiWidget_gotoFavAuth(event) {
this._navToFotkiPage("favorites",this._STAT_CODES.GOTO_FAVAUTH,event,true);
}
,
gotoMyPhotos: function FotkiWidget_gotoMyPhotos(event) {
this._navToFotkiPage("",this._STAT_CODES.GOTO_MYPHOTOS,event,true);
}
,
gotoComments: function FotkiWidget_gotoComments(event) {
this._navToFotkiPage("comments",this._STAT_CODES.GOTO_COMMENTS,event,true);
}
,
gotoUploadPhotos: function FotkiWidget_gotoUploadPhotos(event) {
this._navToFotkiPage("upload",this._STAT_CODES.GOTO_UPLOAD,event);
}
,
_STAT_CODES: {
GOTO_FAVAUTH: 3530,
GOTO_MYPHOTOS: 3510,
GOTO_COMMENTS: 3540,
GOTO_UPLOAD: 3520},
_MODULES: {
utils: "utils.jsm",
counters: "counters.jsm",
yauth: "yauth.jsm"},
_getFotkiURL: function FotkiWidget__getFotkiURL() {
return this.utils.tryCreateFixupURI(this._stringBundle.get("FotkiHost")).spec;
}
,
_loadModules: function FotkiWidget__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);
}

}
,
_navToFotkiPage: function FotkiWidget__navToFotkiPage(page, statAction, origEvent, isConditional) {
var fotkiURL = this._getFotkiURL();
if (isConditional)
{
fotkiURL += "users/" + this.yauth.username + "/" + page;
}
 else
{
fotkiURL += page;
}

if (statAction)
this.API.Statistics.logShortAction(statAction);
this.API.Controls.navigateBrowser({
url: fotkiURL,
eventInfo: origEvent});
}
};
