var A;
A = {
dropper: false,
init: function() {
A.dropper = !(typeof window.FileReader === 'undefined');
A.FORM.init();
A.P.init();
$.fn.DASHBOARD();
$.fn.WIDGET();
return $(window).on('scroll', A.scroll);
},
scroll: function() {
return A.P.scroll();
},
array_keys: function(arr) {
var i, results;
results = [];
for (i in arr) {
results.push(i);
}
return results;
},
// Работа с формами в этом проекте
FORM: {
globalPrepareValidate: function(i, r) {
$(".error_text", i.$wrap).remove();
return i.$wrap.removeClass('error good');
},
globalGood: function(i, r) {
return i.$wrap.addClass('good');
},
globalBad: function(i, r) {
i.$wrap.addClass('error');
return i.$wrap.append($('
' + r.errors.join("
") + '
'));
},
init: function() {
$.fn.FORM('setGlobalGood', A.FORM.globalGood);
$.fn.FORM('setGlobalBad', A.FORM.globalBad);
$.fn.FORM('setPrepareValidate', A.FORM.globalPrepareValidate);
return $.fn.FORM('setGlobalOptions', {
inputActionWithParent: true
});
}
},
reload: function() {
return window.location.reload();
},
display: function(x, y) {
if (y) {
return $(x).show();
} else {
return $(x).hide();
}
},
notify: function(x, html = '') {
return x.queue(function() {
x.html(html).show(300);
return x.dequeue();
});
},
setCookie: function(k, v, date) {
var c, cook, domain;
domain = ' domain=*.' + window.location.host + ';';
domain = ' domain=.' + A.domen + ';';
cook = k + "=" + v + '; expires=' + new Date(date ? date : new Date().getTime() + 5184000000).toGMTString() + '; path=/;';
document.cookie = cook + domain;
c = A.getCookie('k');
if (c !== v) {
document.cookie = cook;
}
return cook;
},
getCookie: function(name) {
var pattern, regexp;
pattern = "(?:; )?" + name + "=([^;]*);?";
regexp = new RegExp(pattern);
if (regexp.test(document.cookie)) {
return decodeURIComponent(RegExp["$1"]);
}
return false;
},
createRequestObject: function() {
if (typeof XMLHttpRequest === 'undefined') {
try {
return new ActiveXObject("Msxml2.XMLHTTP.6.0");
} catch (error) {}
try {
return new ActiveXObject("Msxml2.XMLHTTP.3.0");
} catch (error) {}
try {
return new ActiveXObject("Msxml2.XMLHTTP");
} catch (error) {}
try {
return new ActiveXObject("Microsoft.XMLHTTP");
} catch (error) {}
throw new Error("This browser does not support XMLHttpRequest.");
}
return new XMLHttpRequest();
}
};
$(document).ready(function() {
return A.init();
});
// u - url
// d - data
// c - callback
// cd - callback data
var API;
API = function(u, d = {}, c = null, cd = {}) {
var url;
d['nocache'] = (new Date()).getTime();
url = "/api/" + u + "/";
console.log(url, d);
return $.ajax({
url: url,
type: "POST",
dataType: d.dataType !== void 0 ? d.dataType : "html",
data: d,
success: function(data) {
if (c !== null) {
return typeof c === "function" ? c(data, cd) : void 0;
}
},
error: function() {
return typeof c === "function" ? c({
error: 1
}, cd) : void 0;
}
});
};
A.DROPPER = {
id: 0,
getNextId: function() {
return A.DROPPER.id++;
},
create: function(x, url, data) {
var res;
res = new Array();
if (A.dropper) {
$(x).each(function() {
var c;
c = function(x) {
var isMulti, o;
isMulti = ((data != null ? data.multi : void 0) != null) && data.multi ? true : false;
o = {};
o.logo = $(x);
o.ulogo = $(".over", o.logo);
o.hlogo = $(".drop_help", o.logo);
o.plogo = $(".drop_preview", o.logo);
o.file = $("input[type=file]", o.logo);
if (o.file.length === 0) {
o.file = $('');
o.hlogo.prepend(o.file);
}
//o.hlogo.append($('Выбрать файл'+(if isMulti then 'ы' else '')+''));
o.file = $("input[type=file]", o.logo);
o.file.attr('id', 'file_dropper_id_' + A.DROPPER.getNextId()).change(function() {
var f;
//console.log('changes')
f = document.getElementById(o.file.attr('id'));
//console.log(f.files)
return o.sendFiles(f.files);
});
//console.log(o.file)
//console.log(data)
//if o.logo.hasClass('have')
//o.hlogo.hide();
o.logo.bind('dragenter', function() {
o.logo.addClass('dopper_hover');
return false;
});
o.sendFiles = function(files) {
var bar, f, file, ref, ref1, ref2, ref3, ref4;
//console.log files
o.loaded = 0;
o.links = new Array();
o.count = files.length;
o.plogo.children().remove();
for (file in files) {
f = files[file];
if (f !== void 0 && f.type !== void 0 && ((f != null ? (ref = f.type) != null ? ref.match(/image.*/) : void 0 : void 0) || (f != null ? (ref1 = f.type) != null ? ref1.match(/audio.*/) : void 0 : void 0) || (f != null ? (ref2 = f.type) != null ? ref2.match(/text.*/) : void 0 : void 0) || (f != null ? (ref3 = f.type) != null ? ref3.match(/application.*/) : void 0 : void 0) || (f != null ? (ref4 = f.type) != null ? ref4.match(/video.*/) : void 0 : void 0))) {
//console.log f
bar = function(f) {
var b;
b = {};
//o.hlogo.hide();
o.plogo.show();
b.$div = $('').text(file.name).appendTo(o.plogo);
b.$prog = $('').addClass('progress').appendTo(b.$div);
b.$bar = $('').addClass('bar').appendTo(b.$prog);
b.$btxt = $('').addClass('bartxt').text('0%').appendTo(b.$prog);
b.flogo = file;
b.reader = new FileReader();
b.reader.onloadend = function(e) {
var body, boundary, d, xhr;
//aImg.attr('src', e.target.result);
// ... обновляем инфу о выбранных файлах ...
xhr = A.createRequestObject();
xhr.upload.addEventListener("progress", function(e) {
var pro;
if (e.lengthComputable) {
pro = (e.loaded * 100) / e.total;
b.$bar.css({
width: pro + "%"
});
return b.$btxt.text((pro.toFixed(0)) + "%");
}
//console.log(pro)
}, false);
xhr.onreadystatechange = function() {
if (this.readyState === 4) {
if (this.status === 200) {
//console.log this.responseText
if (((data != null ? data.multi : void 0) != null) && data.multi) {
o.loaded++;
if (this.responseText !== "error") {
o.links.push(this.responseText);
} else {
}
// DOME выдавать какую-нибудь ошибку
//console.log(o.loaded,o.count)
if (((data != null ? data.callback : void 0) != null)) {
data.callback(this.responseText, data.cd);
}
if (o.loaded === o.count) {
if ((data != null ? data.callbackAll : void 0) != null) {
//console.log data, o
data.callbackAll(o.links, data.cd);
}
o.plogo.hide();
return o.hlogo.show();
}
} else {
o.logo.css("background-image", 'url("' + this.responseText + '")').addClass('have');
if (((data != null ? data.callback : void 0) != null)) {
data.callback(this.responseText, data.cd);
} else {
}
//o.logo.css("background-image",'url("'+this.responseText+'")').addClass('have');
return o.plogo.hide();
}
} else {
}
}
};
//* ... ошибка! ... */
xhr.open("POST", url);
boundary = "xxxxxxxxx";
xhr.setRequestHeader("Content-Type", "multipart/form-data; boundary=" + boundary);
xhr.setRequestHeader("Cache-Control", "no-cache");
body = "--" + boundary + "\r\n";
body += "Content-Disposition: form-data; name='myFile'; filename='" + f.name + "'\r\n";
body += 'Content-Type: ' + f.type + '\r\n\r\n';
body += b.reader.result + "\r\n";
body += "--" + boundary + "\r\n";
for (d in data) {
//console.log('data d',d,data[d])
body += 'Content-Disposition: form-data; name="' + d + '"' + "\r\n\r\n";
body += data[d] + "\r\n";
body += "--" + boundary + "\r\n";
}
if (xhr.sendAsBinary) {
// только для firefox
return xhr.sendAsBinary(body);
} else {
// chrome (так гласит спецификация W3C)
return xhr.send(body);
}
};
return b.reader.readAsDataURL(f);
};
bar(f);
}
if (isMulti) {
continue;
} else {
break;
}
}
return false;
};
o.ulogo.bind({
dragover: function() {
return false;
},
dragleave: function() {
o.logo.removeClass('dopper_hover');
return false;
},
drop: function(e) {
o.logo.removeClass('dopper_hover');
o.files = e.originalEvent.dataTransfer.files;
o.sendFiles(o.files);
//console.log(logo)
//console.log(files)
return false;
}
});
return o;
};
return res.push(c(this));
});
}
return res;
}
};
var H;
H = {
menu: {},
selected: {},
top_selected: null,
inited: false,
dir: '', // up | down | left | right
title: null,
data: null,
ready: function() {
if (!H.inited) {
$(window).on('popstate', H.switchByWindow);
H.inited = true;
H.body = $("#content");
return H.title = $("title");
}
},
//H.switch()
reload: function() {
return H.switch({
animate: false
});
},
formGo: function(form) {
var $f, action, path, s;
s = ($f = $(form)).serialize();
action = $f.attr('action');
if (action === void 0) {
action = window.location.pathname;
}
//console.log action
H.go(path = action + '?' + s);
return false;
},
go: function(x, data = null, title = '', reload = true) {
var y;
if (x.substr(0, 1) === '/') {
x = x.substr(1);
}
y = '/' + x;
H.data = data;
history.pushState(data, title, y);
if (reload) {
return H.switch();
}
},
setTitle: function(x) {
return H.title.text(x);
},
switchByWindow: function(x) {
return H.switch(x.state);
},
switch: function(o = {
animate: true
}) {
var path, url;
path = H.parse();
url = path.join("/");
if (url === "/" || url === "") {
url = "/?justContent=1";
} else {
url = `/${url}/?justContent=1`;
}
if (window.location.search.length > 0) {
url += '&' + window.location.search.substr(1);
}
//console.log url
return $.ajax({
url: url,
//url:"/#{url}/?mini=1"
dataType: "JSON",
success: function(data) {
var $data, $html, i, j, ref, ref1, results, s;
//console.log data
if (typeof data.location === "string" && data.location !== "") {
return H.go(data.location);
} else {
H.title.text(data.title);
$data = $(data.content);
$html = $($data[0]);
$("#title").text(data.data.title);
H.setTitle(data.data.title);
//$hide = $(".b_content:not(.hide)").addClass('hide')
//$(".b_content").remove()
//$.fn.TABLE('allDestroy')
H.body.html($html);
A.P.initMini($html);
//A.P.scrollToTop()
if ($data.length > 1) {
results = [];
for (i = j = 1, ref = $data.length - 1; (1 <= ref ? j <= ref : j >= ref); i = 1 <= ref ? ++j : --j) {
s = document.createElement('script');
if ((ref1 = $data[i].tagName) === 'SCRIPT' || ref1 === 'script') {
s.innerHTML = $($data[i]).html();
results.push(H.body[0].appendChild(s));
} else {
results.push(void 0);
}
}
return results;
}
}
},
error: function() {
return console.log('history error ');
}
});
},
SEARCH: {
set: function(s, reload = false) {
var x;
x = window.location.pathname + '?' + s;
return H.go(x, null, '', reload);
},
parse: function() {
var i, pos, res, v, x;
res = {};
if (window.location.search.length > 0) {
x = window.location.search.substr(1).split('&');
for (i in x) {
v = x[i];
pos = v.indexOf('=');
if (pos >= 0) {
res[v.substr(0, pos)] = v.substr(pos + 1);
} else {
res[v] = null;
}
}
}
return res;
},
setValue: function(key, value, reload = false) {
var s, x;
x = H.SEARCH.parse();
x[key] = value;
s = H.SEARCH.toString(x);
return H.SEARCH.set(s);
},
toString: function(a) {
var i, res, v;
res = [];
for (i in a) {
v = a[i];
res.push(i + '=' + (v != null ? v : ''));
}
return res.join('&');
},
get: function(x) {
var e;
try {
return decodeURI(H.SEARCH.parse()[x]);
} catch (error) {
e = error;
return H.SEARCH.parse()[x];
}
}
},
//H.SEARCH.parse()[x]
parse: function() {
var a, i, j, len, o;
a = window.location.pathname.split("/");
o = [];
for (j = 0, len = a.length; j < len; j++) {
i = a[j];
if (i !== "") {
o.push(i);
}
}
return o;
}
};
$(window).ready(H.ready);
A.P = {
scrollTimeout: null,
getScrollTop: function() {
return Math.max(A.P.body.scrollTop(), A.P.$body.scrollTop(), A.P.$html.scrollTop());
},
init: function() {
A.P.body = $("body");
A.P.$body = $("body");
A.P.$html = $("html");
return A.P.initMini();
},
scroll: function() {},
//console.log 'SCROLL'
//A.P.$html.addClass('scroll')
//if A.P.scrollTimeout!=null
// clearTimeout(A.P.scrollTimeout)
//A.P.scrollTimeout = setTimeout(A.P.aScroll,300)
aScroll: function() {
return A.P.$html.removeClass('scroll');
},
initMini: function($html = A.P.body) {
A.P.initPreventLink($html);
$("._module_table", $html).TABLE();
A.P.initForm($html);
$("._ps", $html).perfectScrollbar();
$("[data-input=image]", $html).IMAGE('init_upload');
$("[data-input=video]", $html).VIDEO('init_upload');
$("[data-input=date] input", $html).datetimepicker({
yearOffset: 0,
lang: 'ru',
timepicker: false,
format: 'Y-m-d',
formatDate: 'Y-m-d'
});
$("[data-input=datetime] input", $html).datetimepicker({
yearOffset: 0,
lang: 'ru',
timepicker: true,
format: 'Y-m-d H:i',
formatDate: 'Y-m-d H:i'
});
$("form", $html).FORM();
return $("._toggle_tinymce", $html).click(function() {
var $p, $t, $txt, id;
$t = $(this);
$p = $t.closest('[data-input]');
$txt = $("textarea", $p);
if ($t.is(":checked")) {
id = 'tiny_' + (new Date()).getTime();
$txt.attr('id', id);
$p.attr('data-input', 'tinymce');
$p.attr('data-input-tinymce', id);
A.P.initTiny('#' + id, {
onChange: function() {
console.log('change');
return $txt.val(tinymce.get($txt.attr('id')).getContent());
}
});
} else {
$p.attr('data-input', 'textarea');
tinymce.get($txt.attr('id')).remove();
}
return $t.closest('.ps-container').perfectScrollbar('update');
});
},
initForm: function($html) {
return $("form [type=submit]", $html).click(function() {
var $f, $t;
$f = ($t = $(this)).closest('form');
return $f.data('submit_clicked', $t);
});
},
initTiny: function(selector, options = {}) {
return tinymce.init({
selector: selector,
plugins: 'image',
height: 350,
images_upload_url: '/api/common.image/uploadAccountTinyMCE/',
images_reuse_filename: true,
images_upload_base_path: window.location.origin,
//images_upload_credentials: true,
language: 'ru',
valid_elements: '*[*]',
relative_urls: false,
remove_script_host: true,
document_base_url: window.location.origin,
setup: function(editor) {
//register callbacks to capture the image's original-src at appropriate times
editor.on('BeforeSetContent', function(e) {});
//F.checkMediaSize.apply($(selector),null)
//setImageData( e.target.contentDocument );
return editor.on('change', function(e) {
return typeof options.onChange === "function" ? options.onChange() : void 0;
});
}
});
},
//F.checkMediaSize.apply($(selector),null)
//setImageData( e.target.contentDocument );
initPreventLink: function(x) {
return $("a:not(.prevented)", $(x)).addClass('prevented').click(A.P.preventALink);
},
preventALink: function(e) {
var $t, href;
href = ($t = $(this)).attr('href');
//console.log
if ($t.hasClass('propagation')) {
e.preventDefault();
return e.stopPropagation();
} else if (href === "" || href === "#") {
return e.preventDefault();
} else if (href !== void 0) {
if ($t.hasClass('_to_card')) {
e.preventDefault();
e.stopPropagation();
return $.fn.CARD('openNew', {
api: $t.attr('data-module'),
id: $t.attr('data-id')
});
} else if (href.substr(0, 1) === '/') {
e.preventDefault();
e.stopPropagation();
return H.go($(this).attr('href'));
}
}
}
};
(function($) {
var F;
$.fn.SECTION = function(method) {
if (F[method]) {
return F[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === "object" || !method) {
return F.init.apply(this, arguments);
} else {
return $.error('Метод с именем ' + method + ' не существует для jQuery.SECTION');
}
};
return F = {
init: function() {},
initChangingTheme: function(data) {
var $input, f;
$input = $('[data-name="msPortalSection_theme"]:not(.inited)').addClass('inited').data('send_data', data);
f = $input.closest('._form').FORM();
return $input.on("input:change", F.changeTheme).trigger('input:change');
},
changeTheme: function() {
var $i, $t;
$t = $(this);
$i = Input.init($(this));
return API('core.site.theme/getForm', {
id: $i.value(),
data: $t.data('send_data')
}, function(resp) {
var $data;
$data = $(resp);
A.P.initMini($data);
$(".loaded_form", $t.closest('._form')).html($data);
return $t = null;
});
}
};
})(jQuery);
(function($) {
var F;
$.fn.DASHBOARD = function(method) {
if (F[method]) {
return F[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === "object" || !method) {
return F.init.apply(this, arguments);
} else {
return $.error('Метод с именем ' + method + ' не существует для jQuery.DASHBOARD');
}
};
return F = {
now: 0,
count: 0,
init: function() {
F.container = $("#dashboards");
F.list_wrap = $("#dash_elements");
F.list = $(".dash_li", F.list_wrap);
F.setDashboard(F.list[0].getAttribute('data-id'));
F.addListeners();
return $(".add_dashboard").click(F.openAddDashboard);
},
addListeners: function() {
$(".edit_dashboard", F.list_wrap).click(F.openEditDashboard);
return $(".delete_dashboard", F.list_wrap).click(F.deleteDashboard);
},
deleteDashboard: function(e) {
var id;
e.stopPropagation();
id = e.target.getAttribute('data-id');
return API('ms.dashboard/deleteByIds', {
ids: [id]
}, function() {
return F.reloadList();
});
},
openEditDashboard: function(e) {
var id;
e.stopPropagation();
id = e.target.getAttribute('data-id');
return F.openAddDashboard(e, id);
},
openAddDashboard: function(e, id = 0) {
return $.fn.WINDOW('init', {
options: {
x: 'center', //e.clientX - 10
y: 'center', //e.clientY - 10
api: 'ms.dashboard/renderWindowForm'
},
data: {
id: id
}
});
},
//next:->F.setPage(F.now+1)
//prev:->F.setPage(F.now-1)
setDashboard: function(x) {
F.now = x;
F.list.removeClass('selected');
$(`[data-id=${x}]`, F.list_wrap).addClass('selected');
return API('ms.dashboard/render', {
id: x
}, function(data) {
var $data;
$data = $(data);
F.container.html($data);
F.initDashboard();
A.P.initMini($data);
return $data.on('scroll', A.P.scroll);
});
},
reloadList: function() {
return API('ms.dashboard/getMyList', {}, function(data) {
$("#dash_elements").html(data);
return F.addListeners();
});
},
initIcons: function($html = F.container) {
return $(".icon_td", $html).click(F.iconClick);
},
initDashboard: function() {
$(".test_table_wrap", F.container).perfectScrollbar();
F.initIcons();
$(".grid_dash").sortable({
distance: 5,
handle: '.drag_handle',
stop: function(e, $t, $list) {
var arr, id;
id = $list.parent().attr('data-id');
arr = [];
$list.children().each(function() {
return arr.push(this.getAttribute('data-id'));
});
return API('ms.dashboard/updateWidgetsPos', {
id: id,
pos: arr
});
}
});
// Инициализация таблиц
//$(".dash_cell[data-type=2] .module_table").perfectScrollbar()
$(".dash_cell[data-type=2]").perfectScrollbar();
return $(".dash_cell .widget_delete").click(function(e) {
e.stopPropagation();
return $.fn.WIDGET('deleteWidget', $(this).closest('.dash_cell').attr('data-id'));
});
},
iconClick: function(e) {
var $t, api, id, ref, ref1, ref2, type;
$t = $(this);
api = (ref = $t.attr('data-api')) != null ? ref : 'ms.widget/window';
id = (ref1 = $t.attr('data-id')) != null ? ref1 : 0;
type = (ref2 = $t.attr('data-type')) != null ? ref2 : 0;
return $.fn.WINDOW('init', {
options: {
//x : e.clientX - 10
//y : e.clientY - 10
x: 'center',
y: 'center',
width: 1000,
height: 650,
api: api
},
data: {
id: id,
type: type
}
});
},
addWidget: function(data, id) {
data.id = id;
return API('ms.dashboard/addWidget', data, F.reloadDashboard);
},
reloadDashboard: function() {
var id;
id = $(".dashboard").attr('data-id');
return F.setDashboard(id);
}
};
})(jQuery);
(function($) {
var F;
$.fn.ENTITY = function(method) {
if (F[method]) {
return F[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === "object" || !method) {
return F.init.apply(this, arguments);
} else {
return $.error('Метод с именем ' + method + ' не существует для jQuery.ENTITY');
}
};
return F = {
init: function() {},
updateUI: function(controller) {
// Дополнительные исключения
switch (controller) {
case 'ms.dashboard':
$.fn.DASHBOARD('reloadList');
}
return $('._module_table[data-controller="' + controller + '"]').each(function() {
return $.fn.TABLE('reloadData', $(this).attr('id'));
});
},
copy: function(controller, id, event) {
if (event != null) {
if (typeof event.stopPropagation === "function") {
event.stopPropagation();
}
}
if (event != null) {
if (typeof event.preventDefault === "function") {
event.preventDefault();
}
}
return API(controller + '/copy', {
id,
dataType: "JSON"
}, function(data) {
console.log(data);
return F.openForm(controller, data.id);
});
},
uadd: function(cb) {
var $f, $res, f, submit_button, values;
f = ($f = $(event.target)).FORM();
values = f.json();
$res = $(".res", f.container).hide(300);
submit_button = $f.data('submit_clicked');
f.validate({
success: function() {
var controller;
console.log('formValues', values);
controller = values.controller;
values.dataType = "JSON";
return API(controller + '/uadd', {
values: values,
dataType: "JSON"
}, function(data) {
console.log(data);
A.notify($res, data.m);
F.updateUI(controller);
if (typeof cb === "function") {
cb(data);
}
console.log(submit_button);
if (submit_button != null) {
if (submit_button.hasClass('_save_and_window_close')) {
submit_button.closest('.window').remove();
}
if (submit_button.hasClass('_save')) {
if (parseInt(values._is_new) === 1) {
submit_button.closest('.window').remove();
F.openForm(controller, data.id);
}
}
}
submit_button = null;
return $res = null;
});
}
});
return false;
},
openForm: function(controller, id, init_data) {
var api;
api = controller + (id === 0 ? '/renderWindowForm' : '/renderWindowEdit');
return $.fn.WINDOW('init', {
options: {
//x : e.clientX - 10
//y : e.clientY - 10
x: 'center',
y: 'center',
api: api,
width: 1000,
height: 600
},
data: {
id: id,
init_data: init_data
}
});
}
};
})(jQuery);
(function($) {
var F;
$.fn.IMAGE = function(method) {
if (F[method]) {
return F[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === "object" || !method) {
return F.init.apply(this, arguments);
} else {
return $.error('Метод с именем ' + method + ' не существует для jQuery.IMAGE');
}
};
return F = {
init: function() {},
init_upload: function() {
return $(this).each(function() {
var $t;
$t = $(this);
if (!$t.data('image_drop_inited')) {
$t.data('image_drop_inited', true);
return A.DROPPER.create($t, '/api/common.image/upload/', {
callback: F.aUpload,
cd: {
$t: $t
}
});
}
});
},
aUpload: function(data, cd) {
var $i, $t;
data = JSON.parse(data);
$t = cd.$t;
$i = Input.init($t);
if (data.e === 1) {
} else {
$i.value(data.id);
return $("img", $t).attr('src', data.link);
}
}
};
})(jQuery);
(function($) {
var F;
$.fn.PROFILE = function(method) {
if (F[method]) {
return F[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === "object" || !method) {
return F.init.apply(this, arguments);
} else {
return $.error('Метод с именем ' + method + ' не существует для jQuery.PROFILE');
}
};
return F = {
auth: function() {
var $res, f, s;
f = $(event.target).FORM();
s = f.json();
$res = $(".res", f.container).hide(300);
f.validate({
success: function() {
s.dataType = "JSON";
return API('core.user.account/login', s, function(data) {
if (data.e === 1) {
return A.notify($res, data.m);
} else {
return A.reload();
}
});
}
});
//fail:(res)->console.log('failed',res)
return false;
},
reg: function() {
var $res, f, s;
f = $(event.target).FORM();
s = f.json();
$res = $(".res", f.container).hide(300);
f.validate({
success: function() {
s.dataType = "JSON";
return API('core.user.account/reg', s, function(data) {
if (data.e === 1) {
return A.notify($res, data.m);
} else {
A.setCookie('id', data.id);
A.setCookie('h', data.h);
return A.reload();
}
});
}
});
//fail:(res)->
return false;
},
exit: function() {
return API('core.user.account/exit', {}, function() {
return A.reload();
});
}
};
})(jQuery);
(function($) {
var F;
$.fn.TABLE = function(method) {
if (F[method]) {
return F[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === "object" || !method) {
return F.init.apply(this, arguments);
} else {
return $.error('Метод с именем ' + method + ' не существует для jQuery.TABLE');
}
};
F = {
init: function() {
return $(this).each(function() {
var $actions, $table, $wrap, id;
$table = $(this);
if ($table.hasClass('need_scroll')) {
$table.perfectScrollbar();
}
id = $table.attr('id');
$wrap = $table.closest('.table_wrap');
$actions = $('._actions', $wrap);
$table.data('_wrap', $wrap);
$table.data('_actions', $actions);
F.initThead(id);
F.initTbody(id);
F.resetColumnWidths(id);
F.initPagination(id);
return F.initActions(id);
});
},
setPage: function(id, page) {
return F.setData(id, {
page: page
});
},
setCount: function(id, count) {
return F.setData(id, {
7: count,
page: 0
});
},
setData: function(id, data = {}) {
return API('ms.table/setData', {
name: id,
data: data,
draw_data: F.getDrawData(id),
dataType: "JSON"
}, function(res, cd) {
return F.reloadedData(id, res, cd);
});
},
getFilterData: function(id) {
var arr, filter;
arr = {};
filter = [];
$(`#${id} .filter input`).each(function() {
var name, v;
v = $.trim($(this).val());
if (v !== '') {
name = $(this).attr('name');
arr[name] = v;
return filter.push([7, name, ' LIKE ', "%" + v + "%"]);
}
});
return {
data: arr,
filter
};
},
getDrawData: function(id) {
var d, e, filter_info;
d = {};
try {
d = JSON.parse($(`#${id}`).attr('data-data'));
} catch (error) {
e = error;
d = {};
}
filter_info = F.getFilterData(id);
d.__filter_data = filter_info.data;
d.__filter = filter_info.filter;
return d;
},
reloadData: function(id) {
return API('ms.table/getData', {
name: id,
draw_data: F.getDrawData(id),
dataType: "JSON"
}, function(res, cd) {
return F.reloadedData(id, res, cd);
});
},
reloadedData: function(id, res, cd) {
var $td;
$td = $(res.tbody);
$(`#${id} .cell.td`).remove();
$(`#${id} .table`).append($td);
$('._module_table_pagination[data-id="' + id + '"]').replaceWith($(res.pagination));
F.initPagination(id);
F.initTbody(id);
return $("._ps").perfectScrollbar('update');
},
initPagination: function(id) {
return $('._module_table_pagination[data-id="' + id + '"] a').click(function() {
var page;
page = $(this).attr('data-page');
return F.setPage(id, page);
});
},
initActions: function(id) {
var $actions, $table;
$table = $(`#${id}`);
$actions = $table.data('_actions');
console.log('initActions', $table, $actions, id);
return $("._delete", $actions).click(function() {
return F.deleteChecked(id);
});
},
deleteChecked: function(id) {
var api, controller, ids;
if (confirm("Вы уверены что хотите удалить эти элементы?")) {
ids = F.getCheckedIds(id);
if (ids.length > 0) {
controller = $(`#${id}`).attr('data-controller');
api = controller + '/deleteByIds';
return API(api, {
ids: ids
}, function(data) {
return F.reloadData(id);
});
}
}
},
resetColumnWidths: function(id) {
var $row2, columns, sum;
$row2 = $(`#${id} .sticky[data-sticky=2]`);
columns = '';
sum = 0;
$row2.each(function(i) {
var $t, w;
$t = $(this);
w = $t.attr('data-width');
if ($t.index() === $row2.length) {
columns += '1fr ';
return sum += 50;
} else {
if (w === 'auto') {
if (i === 0) {
columns += $row2.length === 1 ? '1fr ' : 'min-content ';
} else {
//columns += 'min-content '
columns += 'min-content ';
}
} else {
//columns += '1fr '
w = parseFloat(w);
if (isNaN(w)) {
w = $t.outerWidth();
}
columns += w + 'px ';
}
return sum += $t.outerWidth();
}
});
return $(`#${id} .table`).css({
'grid-template-columns': columns,
width: sum
});
},
initThead: function(id) {
var $row1, $row2, $row3, $table, h1, h2;
$table = $(`#${id}`);
$row1 = $(".sticky[data-sticky=1]", $table);
$row2 = $(".sticky[data-sticky=2]", $table);
$row3 = $(".sticky[data-sticky=3]", $table);
h1 = $($row1[0]).outerHeight();
h2 = $($row2[0]).outerHeight();
//h3 = $($row3[0]).height()
$(".filter", $table);
$("input", $table).change(function() {
return F.reloadData(id);
});
$("input", $table).keyup(function() {
var $t, int;
$t = $(this);
int = $t.data('_filter_interval');
if (int != null) {
clearTimeout(int);
}
int = setTimeout(function() {
return F.reloadData(id);
}, 500);
return $t.data('_filter_interval', int);
});
$("select", $table).change(function() {
return F.reloadData(id);
});
h1 = 0;
h2 = $($row2[0]).outerHeight();
//h3 = $($row3[0]).height()
$row2.css({
top: h1
});
$row3.css({
top: h2 + h1
});
$("._set_count:not(.inited)", $table).addClass('inited').change(function() {
return F.setCount(id, $(this).val());
});
$(".resizable_th:not(.inited)", $table).addClass('inited').resizable({
directions: ['right'],
start: function(e, $target) {
return $target.addClass('show_resize_bar').css({
zIndex: 100
});
},
stop: function(e, $target) {
var col_name, w;
$target.removeClass('show_resize_bar').css({
zIndex: 1
}).attr('data-width', w = $target.outerWidth());
F.resetColumnWidths(id);
$target.width('auto');
col_name = $target.attr('data-column');
return API('ms.table/setColumnWidth', {
name: id,
col: col_name,
width: w
});
}
});
$("._add:not(.inited)", $table).addClass('inited').click(function(e) {
var $t, c, d, init_data;
$t = $(e.target);
init_data = {};
try {
d = JSON.parse($table.attr('data-data'));
if ((c = d.form_init_data) !== void 0) {
init_data = c;
}
} catch (error) {
e = error;
console.log(e);
}
//console.log d,init_data
return F.openWindowForm(id, 0, init_data);
});
return $("._check_all", $table).click(function() {
$("._check_tr", $table).prop('checked', $(this).is(":checked"));
return F.checkActions(id);
});
},
getTrID: function($t) {
var $first, $table, c, first, i, id;
$table = $t.closest('._module_table');
id = $table.attr('id');
$first = $(".td:eq(0)", $table);
first = $first.index();
c = F.getColumns(id);
i = Math.floor(($t.index() - first) / c);
return $(`.td:eq(${i * c})`, $table).attr('data-id');
},
openWindowForm: function(table_id = '', id = 0, init_data = {}) {
var controller;
controller = $(`#${table_id}`).attr('data-controller');
return $.fn.ENTITY('openForm', controller, id, init_data);
},
/*
api = controller+(if id==0 then '/renderWindowForm' else '/renderWindowEdit')
$.fn.WINDOW 'init',
options:
#x : e.clientX - 10
#y : e.clientY - 10
x :'center'
y :'center'
api : api
width : 1000
height: 600
data:
id:id
init_data:init_data
*/
getColumns: function(id) {
return $(`#${id} .table`).css('grid-template-columns').split(' ').length;
},
initTbody: function(id) {
var $table, columns, oid, pos;
$table = $(`#${id}`);
$("._check_tr", $table).click(function() {
return F.checkActions(id);
});
if (parseInt($table.attr('data-sortable')) === 1) {
columns = $('[data-sticky=2]', $table).length;
pos = 0;
oid = 0;
return $(".td[data-id]", $table).draggable({
clone: true,
start: function(e, target) {
target.hide();
return target.data('data-id', $(this).attr('data-id'));
},
move: function(e, target) {
var $t, $td, $td2, fi, ni, oid2, p;
$t = $(e.target);
oid = target.attr('data-oid');
if ($t.hasClass('td') && (oid2 = $t.attr('data-oid')) !== oid) {
p = e.offsetY / $t.outerHeight();
$td = $(`.td[data-oid=${oid}]`, $table);
$td2 = $(`.td[data-oid=${oid2}]`, $table);
if (p < 0.5) {
$td.insertBefore($td2.first());
} else {
$td.insertAfter($td2.last());
}
fi = $("[data-id]:eq(0)", $table).index();
ni = $($td[0]).index();
return pos = (ni - fi) / columns;
}
},
// console.log $table.attr('data-controller'),fi,ni,columns,pos
// updatePosForID
//console.log e.target ,target.attr('data-oid')
stop: function(e, target, $target) {
target.remove();
return API($table.attr('data-controller') + '/updatePosForID', {
id: oid,
pos: pos
}, function(data) {
return console.log(data);
});
}
});
}
},
getCheckedIds: function(id) {
var arr;
arr = [];
$(`#${id} ._check_tr:checked`).each(function() {
return arr.push($(this).val());
});
return arr;
},
checkActions: function(id) {
var $actions, $table, ids;
ids = F.getCheckedIds(id);
$table = $(`#${id}`);
$actions = $table.data('_actions');
if (ids.length > 0) {
return $actions.show();
} else {
return $actions.hide();
}
},
clickTable: function(e) {
var $d, $t, isOpen, ref, tr_id;
$t = $(e.target);
$d = $t;
isOpen = true;
if ((ref = e.target.tagName) === 'INPUT' || ref === 'A') {
isOpen = false;
}
if (isOpen) {
if ($d.hasClass('td') || ($d = $t.closest('.td')).length > 0) {
e.stopPropagation();
tr_id = F.getTrID($d);
return F.openWindowForm($t.closest('._module_table').attr('id'), tr_id);
}
}
}
};
return $(document).on('click', F.clickTable);
})(jQuery);
(function($) {
var F;
$.fn.VIDEO = function(method) {
if (F[method]) {
return F[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === "object" || !method) {
return F.init.apply(this, arguments);
} else {
return $.error('Метод с именем ' + method + ' не существует для jQuery.IMAGE');
}
};
return F = {
init: function() {},
init_upload: function() {
var $t;
$t = $(this);
if (!$t.data('video_drop_inited')) {
$t.data('video_drop_inited', true);
return A.DROPPER.create($t, '/api/common.video/upload/', {
callback: F.aUpload,
cd: {
$t: $t
}
});
}
},
aUpload: function(data, cd) {
var $i, $t;
data = JSON.parse(data);
$t = cd.$t;
$i = Input.init($t);
if (data.e === 1) {
} else {
$i.value(data.id);
return $("video", $t).attr('src', data.link);
}
}
};
})(jQuery);
(function($) {
var F;
$.fn.WIDGET = function(method) {
if (F[method]) {
return F[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === "object" || !method) {
return F.init.apply(this, arguments);
} else {
return $.error('Метод с именем ' + method + ' не существует для jQuery.WIDGET');
}
};
return F = {
init: function() {
return $("#start").click(F.openStart);
},
addWidgetToDashboardByEvent: function(e, $drag, $target) {
var id, type;
type = $drag.attr('data-type');
$drag.remove();
id = $target.closest('.dashboard').attr('data-id');
return F.addWidgetToDashboard(type, id);
},
addWidgetToDashboard: function(type, dashboard_id) {
var data;
data = {
type: type
};
return $.fn.DASHBOARD('addWidget', data, dashboard_id);
},
deleteWidget: function(id) {
$(`.dash_cell[data-id=${id}]`).remove();
return API('ms.widget/deleteByIds', {
ids: [id]
}, function(data) {
return console.log(data);
});
},
//# Работа с "Пуском"
startLoaded: function($html) {
$(".drag_widget", $html).draggable({
clone: true,
distance: 5,
cloneConnect: '.grid_dash',
stop: F.addWidgetToDashboardByEvent
});
return $.fn.DASHBOARD('initIcons', $html);
},
openStart: function() {
return $.fn.WINDOW('init', {
options: {
x: 'center',
y: 'center',
width: 960,
height: 720,
api: 'ms.widget/start',
onLoad: F.startLoaded
}
});
}
};
})(jQuery);
(function($) {
var $window, F, W;
$.fn.WINDOW = function(method) {
if (F[method]) {
return F[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === "object" || !method) {
return F.init.apply(this, arguments);
} else {
return $.error('Метод с именем ' + method + ' не существует для jQuery.WINDOW');
}
};
$window = $(window);
W = (function() {
class W {
constructor(data = {}) {
var $w, height, ref, ref1, ref2, ref3, ref4, ref5, ref6, ref7, width, x, y;
this.options = (ref = data.options) != null ? ref : {};
this.init_x = (ref1 = this.options.x) != null ? ref1 : 0;
this.init_y = (ref2 = this.options.y) != null ? ref2 : 0;
this.init_width = (ref3 = this.options.width) != null ? ref3 : 640;
this.init_height = (ref4 = this.options.height) != null ? ref4 : 480;
this.api = (ref5 = this.options.api) != null ? ref5 : '';
this.onLoad = (ref6 = this.options.onLoad) != null ? ref6 : null;
this.data = (ref7 = data.data) != null ? ref7 : {};
$w = $('');
this.$container = $w;
this.$container.data('window', this);
this.$container.mousedown(this.setActive.bind(this));
$w.draggable({
handle: '.window_title_wrap'
});
$w.resizable({
stop: function(e, $target) {
var ref8;
data = (ref8 = $target.data('data')) != null ? ref8 : {};
data.width = $target.width();
data.height = $target.height();
return API('ms.widget/saveWidthHeight', data);
}
});
$("body").append($w);
width = 800; //@init_width
height = 400; //@init_height
x = this.init_x;
y = this.init_y;
if (x === 'center') {
x = parseInt(($window.width() - width) / 2);
}
if (y === 'center') {
y = parseInt(($window.height() - height) / 2);
}
if (x < 0) {
x = 0;
}
if (y < 0) {
y = 0;
}
$w.css({
'transform': 'translate(' + x + 'px,' + y + 'px)',
zIndex: $(".window").length,
'width': width,
'height': height
});
$w.on('destroyed', this.destroy.bind(this));
$(".window_close", $w).on('click', this.close.bind(this));
$(".window_reload", $w).on('click', this.reload.bind(this));
$(".window_fullscreen", $w).on('click', this.toggleFullscreen.bind(this));
this.$content_wrap = $(".window_content_wrap", $w);
this.$content_wrap.perfectScrollbar();
this.$content = $(".window_content", $w);
this.$title = $(".window_title", $w);
this.firstLoad = true;
this.reload();
}
toggleFullscreen() {
if (this.$container.hasClass('fullscreen')) {
return this.fullscreenReset();
} else {
return this.fullscreen();
}
}
fullscreenReset() {
this.$container.removeClass('fullscreen');
this.$container.resizable('enable');
return this.$content_wrap.perfectScrollbar('update');
}
fullscreen() {
this.$container.addClass('fullscreen');
this.$content_wrap.perfectScrollbar('update');
return this.$container.resizable('disable');
}
minimize() {}
setTitle(x) {
return this.$title.html(x);
}
setActive() {
var $cont, $w, arr, read, write;
arr = {};
$cont = this.$container;
$w = $(".window");
read = fastdom.measure(function() {
return $w.each(function() {
if (this !== $cont[0]) {
return arr[this.style.zIndex] = this;
}
});
});
return write = fastdom.mutate(function() {
var a, i;
a = A.array_keys(arr);
a.sort();
for (i in a) {
arr[a[i]].style.zIndex = parseInt(i) + 1;
}
return $cont[0].style.zIndex = $w.length;
}).then(function() {
fastdom.clear(read);
return fastdom.clear(write);
});
}
startLoad() {
this.$container.addClass('loading');
return this.$content.html('Загрузка');
}
finishLoad(data, cd) {
var $data, c, css, isEdit, t, x, y;
this.$container.addClass('loaded');
t = this.$container;
setTimeout(function() {
t.removeClass('loading loaded');
return t = null;
}, 500);
$data = $(data);
this.$content.html($data);
A.P.initMini($data);
if (typeof this.onLoad === "function") {
this.onLoad($data);
}
isEdit = $(".edit_panel", $data).length > 0;
this.$container.toggleClass('window_leftmenu', isEdit);
if (isEdit) {
$(".tab_link", $data).click(function() {
var $t;
$t = $(this);
$(".tab_link", $data).removeClass('selected');
$(".edit_tabs .tab", $data).hide();
if ($t.is(":last-child")) {
$(".edit_tabs .tab", $data).show();
$t.removeClass('show');
} else {
$t.addClass('selected');
$(".edit_tabs .tab:eq(" + $t.index() + ")", $data).show();
console.log($(".edit_tabs .tab:last-child", $data));
$(".tab_link:last-child", $data).addClass('show');
}
return $("._ps", $data).perfectScrollbar('update');
});
}
if (((c = $data.attr('data-data')) != null) && c !== '') {
try {
data = JSON.parse(c);
if (data.no_scroll) {
this.$content_wrap.perfectScrollbar('disable');
this.$container.addClass('window_no_scroll');
}
if (data.table) {
this.$container.addClass('window_table');
}
if (data.data) {
this.$container.data('data', data.data);
}
css = {};
if (data.width != null) {
css.width = Math.min(data.width, $window.width() * 0.9);
}
if (data.height != null) {
css.height = Math.min(data.height, $window.height() * 0.9);
}
x = this.$container.offset().left;
y = this.$container.offset().top;
if (this.firstLoad) {
if (this.init_x === 'center' && (css.width != null)) {
x = parseInt(($window.width() - css.width) / 2);
}
if (this.init_y === 'center' && (css.height != null)) {
y = parseInt(($window.height() - css.height) / 2);
}
}
css.transform = 'translate(' + x + 'px,' + y + 'px)';
this.$container.css(css);
if (data.title != null) {
this.setTitle(data.title);
}
} catch (error) {}
}
return this.firstLoad = false;
}
reload() {
this.startLoad();
API(this.api, this.data, this.finishLoad.bind(this));
return false;
}
close() {
$("[data-input=tinymce]", this.$container).each(function() {
var a;
a = tinymce.get($(this).attr('data-input-tinymce'));
console.log('want remove a', a);
if (a !== null && a !== void 0) {
return a.remove();
}
});
return this.$container.remove();
}
destroy() {
this.$content_wrap = null;
this.$container = null;
return this.$content = null;
}
};
W.zIndex = 0;
return W;
}).call(this);
return F = {
init: function(data) {
return new W(data);
}
};
})(jQuery);
(function($) {
var F;
$.fn.ITEM = function(method) {
if (F[method]) {
return F[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === "object" || !method) {
return F.init.apply(this, arguments);
} else {
return $.error('Метод с именем ' + method + ' не существует для jQuery.ITEM');
}
};
return F = {
init: function() {},
initChangingProperty: function(data) {
var $input, f;
$input = $('[data-name="shopItemValue_property"]:not(.inited)').addClass('inited');
f = $input.closest('._form').FORM();
$input.data('item_id', $('[data-name="shopItemValue_item"]', f.container).val());
return $input.on("input:change", F.changeProperty).trigger('input:change');
},
changeProperty: function() {
var $i, $t;
$t = $(this);
$i = Input.init($(this));
return API('shop.item.value/getValues', {
id: $i.value(),
item_id: $t.data('item_id')
}, function(resp) {
var $data;
$data = $(resp);
A.P.initMini($data);
$(".loaded_values", $t.closest('._form')).html($data);
return $t = null;
});
},
saveCategories: function(id) {
var $list, $w, arr, w;
arr = [];
$list = $(`[data-item-categories=${id}]`);
$("input:checked", $list).each(function() {
return arr.push($(this).val());
});
$w = $list.closest('.window');
if ($w.length > 0) {
w = $w.data('window');
w.close();
return API('shop.category.item/setCategories', {
id: id,
arr: arr
}, function(data) {
console.log(data);
return $.fn.ENTITY('updateUI', 'shop.category.item');
});
}
}
};
})(jQuery);
(function($) {
var F;
$.fn.SHOP = function(method) {
if (F[method]) {
return F[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === "object" || !method) {
return F.init.apply(this, arguments);
} else {
return $.error('Метод с именем ' + method + ' не существует для jQuery.SHOP');
}
};
return F = {
init: function() {},
saveCategories: function(id) {
var $list, $w, arr, w;
console.log('saveCategories', id);
arr = [];
$list = $(`[data-shop-categories=${id}]`);
$("input:checked", $list).each(function() {
return arr.push($(this).val());
});
console.log('want ', arr);
$w = $list.closest('.window');
if ($w.length > 0) {
w = $w.data('window');
w.close();
return API('shop.shop.category/setCategories', {
id: id,
arr: arr
}, function() {
return $.fn.ENTITY('updateUI', 'shop.shop.category');
});
}
},
initCategories: function() {
return $(".shop_categories:not(.inited)").addClass('inited').each(function() {
$("input:checked").each(function() {
var $par;
$par = $(this).closest('li');
return $("> ul ", $par).hide();
});
return $("input[type=checkbox]").click(F.checkShopCategories);
});
},
checkShopCategories: function() {
var $par, $t, checked;
$t = $(this);
$par = $(this).closest('li');
checked = $t.is(":checked");
$("> ul ", $par).toggle(!checked);
$("> ul ul", $par).show(checked);
return $("> ul input[type=checkbox]", $par).prop('checked', false);
}
};
})(jQuery);
(function($) {
var F;
$.fn.PROJECT = function(method) {
console.log('PROJECT method', method);
if (F[method]) {
return F[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === "object" || !method) {
return F.init.apply(this, arguments);
} else {
return $.error('Метод с именем ' + method + ' не существует для jQuery.PROJECT');
}
};
return F = {
init: function() {},
changePipeline: function($input, id) {
console.log('changePipeline', $input, id);
return API('pm.pipeline.stage/getListByPipeline', {
pipeline: id,
dataType: "JSON"
}, function(data) {
var i, res;
res = '';
for (i in data) {
res += '';
}
return $input.$input.html(res);
});
}
};
})(jQuery);