2016-01-11 02:25:30 +01:00
|
|
|
(function (global, factory) {
|
|
|
|
if (typeof define === "function" && define.amd) {
|
2016-07-28 06:03:09 +02:00
|
|
|
define('ss.GridField', ['jQuery', 'i18n'], factory);
|
2016-01-11 02:25:30 +01:00
|
|
|
} else if (typeof exports !== "undefined") {
|
2016-07-28 06:03:09 +02:00
|
|
|
factory(require('jQuery'), require('i18n'));
|
2016-01-11 02:25:30 +01:00
|
|
|
} else {
|
|
|
|
var mod = {
|
|
|
|
exports: {}
|
|
|
|
};
|
|
|
|
factory(global.jQuery, global.i18n);
|
|
|
|
global.ssGridField = mod.exports;
|
|
|
|
}
|
|
|
|
})(this, function (_jQuery, _i18n) {
|
2016-02-12 04:00:15 +01:00
|
|
|
'use strict';
|
|
|
|
|
2016-01-11 02:25:30 +01:00
|
|
|
var _jQuery2 = _interopRequireDefault(_jQuery);
|
|
|
|
|
|
|
|
var _i18n2 = _interopRequireDefault(_i18n);
|
|
|
|
|
|
|
|
function _interopRequireDefault(obj) {
|
|
|
|
return obj && obj.__esModule ? obj : {
|
|
|
|
default: obj
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
_jQuery2.default.entwine('ss', function ($) {
|
2016-07-01 03:37:29 +02:00
|
|
|
$('.grid-field').entwine({
|
2016-03-04 04:40:54 +01:00
|
|
|
|
2016-01-11 02:25:30 +01:00
|
|
|
reload: function reload(ajaxOpts, successCallback) {
|
|
|
|
var self = this,
|
|
|
|
form = this.closest('form'),
|
|
|
|
focusedElName = this.find(':input:focus').attr('name'),
|
|
|
|
data = form.find(':input').serializeArray();
|
2016-03-04 04:40:54 +01:00
|
|
|
|
2016-01-11 02:25:30 +01:00
|
|
|
if (!ajaxOpts) ajaxOpts = {};
|
|
|
|
if (!ajaxOpts.data) ajaxOpts.data = [];
|
|
|
|
ajaxOpts.data = ajaxOpts.data.concat(data);
|
|
|
|
|
|
|
|
if (window.location.search) {
|
|
|
|
ajaxOpts.data = window.location.search.replace(/^\?/, '') + '&' + $.param(ajaxOpts.data);
|
|
|
|
}
|
|
|
|
|
|
|
|
form.addClass('loading');
|
2016-03-04 04:40:54 +01:00
|
|
|
|
2016-01-11 02:25:30 +01:00
|
|
|
$.ajax($.extend({}, {
|
2016-03-04 04:40:54 +01:00
|
|
|
headers: { "X-Pjax": 'CurrentField' },
|
2016-01-11 02:25:30 +01:00
|
|
|
type: "POST",
|
|
|
|
url: this.data('url'),
|
|
|
|
dataType: 'html',
|
|
|
|
success: function success(data) {
|
|
|
|
self.empty().append($(data).children());
|
2016-03-04 04:40:54 +01:00
|
|
|
|
2016-01-11 02:25:30 +01:00
|
|
|
if (focusedElName) self.find(':input[name="' + focusedElName + '"]').focus();
|
|
|
|
|
|
|
|
if (self.find('.filter-header').length) {
|
|
|
|
var content;
|
|
|
|
if (ajaxOpts.data[0].filter == "show") {
|
|
|
|
content = '<span class="non-sortable"></span>';
|
|
|
|
self.addClass('show-filter').find('.filter-header').show();
|
|
|
|
} else {
|
2016-07-01 03:37:29 +02:00
|
|
|
content = '<button type="button" name="showFilter" class="btn font-icon-search btn--no-text btn--icon-large grid-field__filter-open ss-gridfield-button-filter trigger"></button>';
|
2016-01-11 02:25:30 +01:00
|
|
|
self.removeClass('show-filter').find('.filter-header').hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
self.find('.sortable-header th:last').html(content);
|
|
|
|
}
|
|
|
|
|
|
|
|
form.removeClass('loading');
|
|
|
|
if (successCallback) successCallback.apply(this, arguments);
|
|
|
|
self.trigger('reload', self);
|
|
|
|
},
|
|
|
|
error: function error(e) {
|
|
|
|
alert(_i18n2.default._t('GRIDFIELD.ERRORINTRANSACTION'));
|
|
|
|
form.removeClass('loading');
|
|
|
|
}
|
|
|
|
}, ajaxOpts));
|
|
|
|
},
|
|
|
|
showDetailView: function showDetailView(url) {
|
|
|
|
window.location.href = url;
|
|
|
|
},
|
|
|
|
getItems: function getItems() {
|
|
|
|
return this.find('.ss-gridfield-item');
|
|
|
|
},
|
2016-03-04 04:40:54 +01:00
|
|
|
|
2016-01-11 02:25:30 +01:00
|
|
|
setState: function setState(k, v) {
|
|
|
|
var state = this.getState();
|
|
|
|
state[k] = v;
|
|
|
|
this.find(':input[name="' + this.data('name') + '[GridState]"]').val(JSON.stringify(state));
|
|
|
|
},
|
2016-03-04 04:40:54 +01:00
|
|
|
|
2016-01-11 02:25:30 +01:00
|
|
|
getState: function getState() {
|
|
|
|
return JSON.parse(this.find(':input[name="' + this.data('name') + '[GridState]"]').val());
|
|
|
|
}
|
|
|
|
});
|
2016-03-04 04:40:54 +01:00
|
|
|
|
2016-07-01 03:37:29 +02:00
|
|
|
$('.grid-field *').entwine({
|
2016-01-11 02:25:30 +01:00
|
|
|
getGridField: function getGridField() {
|
2016-07-01 03:37:29 +02:00
|
|
|
return this.closest('.grid-field');
|
2016-01-11 02:25:30 +01:00
|
|
|
}
|
|
|
|
});
|
2016-03-04 04:40:54 +01:00
|
|
|
|
2016-07-01 03:37:29 +02:00
|
|
|
$('.grid-field :button[name=showFilter]').entwine({
|
2016-01-11 02:25:30 +01:00
|
|
|
onclick: function onclick(e) {
|
|
|
|
$('.filter-header').show('slow').find(':input:first').focus();
|
2016-07-01 03:37:29 +02:00
|
|
|
this.closest('.grid-field').addClass('show-filter');
|
2016-01-11 02:25:30 +01:00
|
|
|
this.parent().html('<span class="non-sortable"></span>');
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
});
|
2016-03-04 04:40:54 +01:00
|
|
|
|
2016-07-01 03:37:29 +02:00
|
|
|
$('.grid-field .ss-gridfield-item').entwine({
|
2016-01-11 02:25:30 +01:00
|
|
|
onclick: function onclick(e) {
|
|
|
|
if ($(e.target).closest('.action').length) {
|
|
|
|
this._super(e);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var editLink = this.find('.edit-link');
|
|
|
|
if (editLink.length) this.getGridField().showDetailView(editLink.prop('href'));
|
|
|
|
},
|
|
|
|
onmouseover: function onmouseover() {
|
|
|
|
if (this.find('.edit-link').length) this.css('cursor', 'pointer');
|
|
|
|
},
|
|
|
|
onmouseout: function onmouseout() {
|
|
|
|
this.css('cursor', 'default');
|
|
|
|
}
|
|
|
|
});
|
2016-03-04 04:40:54 +01:00
|
|
|
|
2016-07-01 03:37:29 +02:00
|
|
|
$('.grid-field .action:button').entwine({
|
2016-01-11 02:25:30 +01:00
|
|
|
onclick: function onclick(e) {
|
|
|
|
var filterState = 'show';
|
|
|
|
if (this.button('option', 'disabled')) {
|
|
|
|
e.preventDefault();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-01 03:37:29 +02:00
|
|
|
if (this.hasClass('ss-gridfield-button-close') || !this.closest('.grid-field').hasClass('show-filter')) {
|
2016-01-11 02:25:30 +01:00
|
|
|
filterState = 'hidden';
|
|
|
|
}
|
|
|
|
|
2016-03-04 04:40:54 +01:00
|
|
|
this.getGridField().reload({ data: [{ name: this.attr('name'), value: this.val(), filter: filterState }] });
|
2016-01-11 02:25:30 +01:00
|
|
|
e.preventDefault();
|
2016-03-04 04:40:54 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
actionurl: function actionurl() {
|
|
|
|
var btn = this.closest(':button'),
|
|
|
|
grid = this.getGridField(),
|
|
|
|
form = this.closest('form'),
|
|
|
|
data = form.find(':input.gridstate').serialize(),
|
|
|
|
csrf = form.find('input[name="SecurityID"]').val();
|
|
|
|
|
|
|
|
data += "&" + encodeURIComponent(btn.attr('name')) + '=' + encodeURIComponent(btn.val());
|
|
|
|
|
|
|
|
if (csrf) {
|
|
|
|
data += "&SecurityID=" + encodeURIComponent(csrf);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window.location.search) {
|
|
|
|
data = window.location.search.replace(/^\?/, '') + '&' + data;
|
|
|
|
}
|
|
|
|
|
|
|
|
var connector = grid.data('url').indexOf('?') == -1 ? '?' : '&';
|
|
|
|
|
|
|
|
return $.path.makeUrlAbsolute(grid.data('url') + connector + data, $('base').attr('href'));
|
2016-01-11 02:25:30 +01:00
|
|
|
}
|
2016-03-04 04:40:54 +01:00
|
|
|
|
2016-01-11 02:25:30 +01:00
|
|
|
});
|
2016-03-04 04:40:54 +01:00
|
|
|
|
2016-07-01 03:37:29 +02:00
|
|
|
$('.grid-field .add-existing-autocompleter').entwine({
|
2016-01-11 02:25:30 +01:00
|
|
|
onbuttoncreate: function onbuttoncreate() {
|
|
|
|
var self = this;
|
2016-03-04 04:40:54 +01:00
|
|
|
|
2016-01-11 02:25:30 +01:00
|
|
|
this.toggleDisabled();
|
2016-03-04 04:40:54 +01:00
|
|
|
|
2016-01-11 02:25:30 +01:00
|
|
|
this.find('input[type="text"]').on('keyup', function () {
|
|
|
|
self.toggleDisabled();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onunmatch: function onunmatch() {
|
|
|
|
this.find('input[type="text"]').off('keyup');
|
|
|
|
},
|
|
|
|
toggleDisabled: function toggleDisabled() {
|
|
|
|
var $button = this.find('.ss-ui-button'),
|
|
|
|
$input = this.find('input[type="text"]'),
|
|
|
|
inputHasValue = $input.val() !== '',
|
|
|
|
buttonDisabled = $button.is(':disabled');
|
|
|
|
|
|
|
|
if (inputHasValue && buttonDisabled || !inputHasValue && !buttonDisabled) {
|
|
|
|
$button.button("option", "disabled", !buttonDisabled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2016-03-04 04:40:54 +01:00
|
|
|
|
2016-07-01 03:37:29 +02:00
|
|
|
$('.grid-field .grid-field__col-compact .action.gridfield-button-delete, .cms-edit-form .btn-toolbar button.action.action-delete').entwine({
|
2016-01-11 02:25:30 +01:00
|
|
|
onclick: function onclick(e) {
|
|
|
|
if (!confirm(_i18n2.default._t('TABLEFIELD.DELETECONFIRMMESSAGE'))) {
|
|
|
|
e.preventDefault();
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
this._super(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2016-03-04 04:40:54 +01:00
|
|
|
|
2016-07-01 03:37:29 +02:00
|
|
|
$('.grid-field .action.gridfield-button-print').entwine({
|
2016-01-11 02:25:30 +01:00
|
|
|
UUID: null,
|
|
|
|
onmatch: function onmatch() {
|
|
|
|
this._super();
|
|
|
|
this.setUUID(new Date().getTime());
|
|
|
|
},
|
|
|
|
onunmatch: function onunmatch() {
|
|
|
|
this._super();
|
|
|
|
},
|
|
|
|
onclick: function onclick(e) {
|
2016-03-04 04:40:54 +01:00
|
|
|
var url = this.actionurl();
|
|
|
|
window.open(url);
|
|
|
|
e.preventDefault();
|
2016-01-11 02:25:30 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2016-03-04 04:40:54 +01:00
|
|
|
|
2016-01-11 02:25:30 +01:00
|
|
|
$('.ss-gridfield-print-iframe').entwine({
|
|
|
|
onmatch: function onmatch() {
|
|
|
|
this._super();
|
|
|
|
|
|
|
|
this.hide().bind('load', function () {
|
|
|
|
this.focus();
|
|
|
|
var ifWin = this.contentWindow || this;
|
|
|
|
ifWin.print();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onunmatch: function onunmatch() {
|
|
|
|
this._super();
|
|
|
|
}
|
|
|
|
});
|
2016-03-04 04:40:54 +01:00
|
|
|
|
2016-07-01 03:37:29 +02:00
|
|
|
$('.grid-field .action.no-ajax').entwine({
|
2016-01-11 02:25:30 +01:00
|
|
|
onclick: function onclick(e) {
|
2016-03-04 04:40:54 +01:00
|
|
|
window.location.href = this.actionurl();
|
|
|
|
e.preventDefault();
|
2016-01-11 02:25:30 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2016-03-04 04:40:54 +01:00
|
|
|
|
2016-07-01 03:37:29 +02:00
|
|
|
$('.grid-field .action-detail').entwine({
|
2016-01-11 02:25:30 +01:00
|
|
|
onclick: function onclick() {
|
|
|
|
this.getGridField().showDetailView($(this).prop('href'));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2016-03-04 04:40:54 +01:00
|
|
|
|
2016-07-01 03:37:29 +02:00
|
|
|
$('.grid-field[data-selectable]').entwine({
|
2016-01-11 02:25:30 +01:00
|
|
|
getSelectedItems: function getSelectedItems() {
|
|
|
|
return this.find('.ss-gridfield-item.ui-selected');
|
|
|
|
},
|
2016-03-04 04:40:54 +01:00
|
|
|
|
2016-01-11 02:25:30 +01:00
|
|
|
getSelectedIDs: function getSelectedIDs() {
|
|
|
|
return $.map(this.getSelectedItems(), function (el) {
|
|
|
|
return $(el).data('id');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2016-07-01 03:37:29 +02:00
|
|
|
$('.grid-field[data-selectable] .ss-gridfield-items').entwine({
|
2016-01-11 02:25:30 +01:00
|
|
|
onadd: function onadd() {
|
|
|
|
this._super();
|
|
|
|
|
|
|
|
this.selectable();
|
|
|
|
},
|
|
|
|
onremove: function onremove() {
|
|
|
|
this._super();
|
|
|
|
if (this.data('selectable')) this.selectable('destroy');
|
|
|
|
}
|
|
|
|
});
|
2016-03-04 04:40:54 +01:00
|
|
|
|
2016-07-01 03:37:29 +02:00
|
|
|
$('.grid-field .filter-header :input').entwine({
|
2016-01-11 02:25:30 +01:00
|
|
|
onmatch: function onmatch() {
|
2016-07-01 03:37:29 +02:00
|
|
|
var filterbtn = this.closest('.extra').find('.ss-gridfield-button-filter'),
|
|
|
|
resetbtn = this.closest('.extra').find('.ss-gridfield-button-reset');
|
2016-01-11 02:25:30 +01:00
|
|
|
|
|
|
|
if (this.val()) {
|
|
|
|
filterbtn.addClass('filtered');
|
|
|
|
resetbtn.addClass('filtered');
|
|
|
|
}
|
|
|
|
this._super();
|
|
|
|
},
|
|
|
|
onunmatch: function onunmatch() {
|
|
|
|
this._super();
|
|
|
|
},
|
|
|
|
onkeydown: function onkeydown(e) {
|
|
|
|
if (this.closest('.ss-gridfield-button-reset').length) return;
|
2016-03-04 04:40:54 +01:00
|
|
|
|
2016-07-01 03:37:29 +02:00
|
|
|
var filterbtn = this.closest('.extra').find('.ss-gridfield-button-filter'),
|
|
|
|
resetbtn = this.closest('.extra').find('.ss-gridfield-button-reset');
|
2016-01-11 02:25:30 +01:00
|
|
|
|
|
|
|
if (e.keyCode == '13') {
|
|
|
|
var btns = this.closest('.filter-header').find('.ss-gridfield-button-filter');
|
|
|
|
var filterState = 'show';
|
2016-07-01 03:37:29 +02:00
|
|
|
if (this.hasClass('ss-gridfield-button-close') || !this.closest('.grid-field').hasClass('show-filter')) {
|
2016-01-11 02:25:30 +01:00
|
|
|
filterState = 'hidden';
|
|
|
|
}
|
|
|
|
|
2016-03-04 04:40:54 +01:00
|
|
|
this.getGridField().reload({ data: [{ name: btns.attr('name'), value: btns.val(), filter: filterState }] });
|
2016-01-11 02:25:30 +01:00
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
filterbtn.addClass('hover-alike');
|
|
|
|
resetbtn.addClass('hover-alike');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2016-03-04 04:40:54 +01:00
|
|
|
|
2016-07-01 03:37:29 +02:00
|
|
|
$(".grid-field .relation-search").entwine({
|
2016-01-11 02:25:30 +01:00
|
|
|
onfocusin: function onfocusin(event) {
|
|
|
|
this.autocomplete({
|
|
|
|
source: function source(request, response) {
|
|
|
|
var searchField = $(this.element);
|
|
|
|
var form = $(this.element).closest("form");
|
|
|
|
$.ajax({
|
|
|
|
headers: {
|
|
|
|
"X-Pjax": 'Partial'
|
|
|
|
},
|
2016-07-28 02:05:36 +02:00
|
|
|
dataType: 'json',
|
2016-01-11 02:25:30 +01:00
|
|
|
type: "GET",
|
|
|
|
url: $(searchField).data('searchUrl'),
|
|
|
|
data: encodeURIComponent(searchField.attr('name')) + '=' + encodeURIComponent(searchField.val()),
|
2016-07-28 02:05:36 +02:00
|
|
|
success: response,
|
2016-01-11 02:25:30 +01:00
|
|
|
error: function error(e) {
|
|
|
|
alert(_i18n2.default._t('GRIDFIELD.ERRORINTRANSACTION', 'An error occured while fetching data from the server\n Please try again later.'));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
select: function select(event, ui) {
|
2016-07-28 02:05:36 +02:00
|
|
|
var hiddenField = $('<input type="hidden" name="relationID" class="action_gridfield_relationfind" />');
|
|
|
|
hiddenField.val(ui.item.id);
|
2016-07-01 03:37:29 +02:00
|
|
|
$(this).closest(".grid-field").find(".action_gridfield_relationfind").replaceWith(hiddenField);
|
|
|
|
var addbutton = $(this).closest(".grid-field").find(".action_gridfield_relationadd");
|
2016-01-11 02:25:30 +01:00
|
|
|
if (addbutton.data('button')) {
|
|
|
|
addbutton.button('enable');
|
|
|
|
} else {
|
|
|
|
addbutton.removeAttr('disabled');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2016-03-04 04:40:54 +01:00
|
|
|
|
2016-07-01 03:37:29 +02:00
|
|
|
$(".grid-field .pagination-page-number input").entwine({
|
2016-01-11 02:25:30 +01:00
|
|
|
onkeydown: function onkeydown(event) {
|
|
|
|
if (event.keyCode == 13) {
|
|
|
|
var newpage = parseInt($(this).val(), 10);
|
2016-03-04 04:40:54 +01:00
|
|
|
|
2016-01-11 02:25:30 +01:00
|
|
|
var gridfield = $(this).getGridField();
|
2016-03-04 04:40:54 +01:00
|
|
|
gridfield.setState('GridFieldPaginator', { currentPage: newpage });
|
2016-01-11 02:25:30 +01:00
|
|
|
gridfield.reload();
|
2016-03-04 04:40:54 +01:00
|
|
|
|
2016-01-11 02:25:30 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2016-07-28 02:05:36 +02:00
|
|
|
});
|