Your IP : 18.219.40.177
/**
* Module provide store in site
* @param {object} window global object
* @param {function} $ jQuery library
* @param {object} EventMgr EventMgr library
* @param {object} App Application
* @return {object} api
*/
App.Store = function(window, $, EventMgr, App) {
'use strict';
var project = pageInfo.project || 1;
function $formContent() {
return App.Dom.byId('isp-store-wrapper');
}
//init store func, get startform
function storeInit() {
if (pageInfo.startform) {
var params = App.u.parseParams(pageInfo.startform);
// params.authinfo = 'hank@tsjee.ru:q1w2e';
//params.project = project;
params.storemode = 'on';
EventMgr.trigger('ajaxRequest', {
param: params,
outtype: 'json',
trfunc: 'storeResp',
invar: {
showcaseForm: true
}
});
}
}
//caught event & set type of content
function preRespActions(e, data) {
var obj = data;
//caught fatal error
if (obj.form || obj.formParam) {
obj.type = 'showcaseForm';
obj.showcase = true;
EventMgr.trigger('ajaxResponse', obj);
EventMgr.trigger('storeBasketForceUpdate');
} else if (obj.error) {
EventMgr.trigger('storeError', obj);
//type url handler
} else if (obj.ok && obj.location) {
window.location = obj.location;
}
}
//insert form in tab-content box
function insertStoreForm(e, data) {
var html = data;
$formContent().innerHTML = html;
EventMgr.trigger('tabLoadingHide', { tabId: 'tab0' });
EventMgr.trigger('appendForm', { tabId: 'tab0' });
}
//ajax request hook, set type json & change trFunc
function ajaxRequestHook(data) {
var options = data;
//options.param.authinfo = 'hank@tsjee.ru:q1w2e';
//options.param.project = project;
options.param.storemode = 'on';
delete options.param.callback;
if (options.trfunc === 'ajaxResponse' ||
options.trfunc === 'ajaxFormResponse') {
options.trfunc = 'storeResp';
}
}
function ajaxResponseHook(data) {
}
function storeError(e, data) {
var html = templates.fatalAlert({
msg: data.ermsg
});
$formContent().innerHTML = html;
}
function openBasket(e, data) {
var params = { func: 'basket' };
//params.authinfo = 'hank@tsjee.ru:q1w2e';
//params.project = project;
params.storemode = 'on';
EventMgr.trigger('ajaxRequest', {
param: params,
outtype: 'json',
trfunc: 'storeResp',
invar: {
showcaseForm: true
}
});
}
function init() {
EventMgr.bind('readyShowcaseFormHtml', insertStoreForm);
EventMgr.bind('storeResp', preRespActions);
EventMgr.bind('storeLoad', storeInit);
EventMgr.bind('storeError', storeError);
EventMgr.bind('openStoreBasket', openBasket);
//add hooks for ajax request/response
if (App.AjaxHelper) {
if (App.AjaxHelper.addRequestHook &&
typeof App.AjaxHelper.addRequestHook === 'function') {
App.AjaxHelper.addRequestHook(ajaxRequestHook);
}
// if (App.AjaxHelper.addResponseHook &&
// typeof App.AjaxHelper.addResponseHook === 'function') {
// App.AjaxHelper.addResponseHook(ajaxResponseHook);
// }
}
}
var api = {
init: init
};
return api;
} (window, $, EventMgr, App);