Commit 4f3bb3e2 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

common functionality exrtacted to separate method

parent 242a377a
"use strict";
var $ = require('jquery');
/* exported logger */
/* exported Promise*/
......@@ -85,6 +87,29 @@ AbstractAdminPanel.prototype.bindUserGuiPreference = function (params) {
};
/**
*
* @param {Object} param
* @param {HTMLElement} param.element
* @param {string} param.preferenceName
*/
AbstractAdminPanel.prototype.bindDataTablePageLengthToUserPreference = function (param) {
var jQueryObject = $(param.element);
return this.bindUserGuiPreference({
jQueryObject: jQueryObject,
event: 'length.dt',
preferenceName: param.preferenceName,
defaultValue: '10',
getter: function () {
return jQueryObject.DataTable().page.len() + '';
},
setter: function (value) {
return jQueryObject.DataTable().page.len(value).draw();
}
})
};
/**
*
* @returns {Promise}
......
......@@ -141,17 +141,9 @@ ConfigurationAdminPanel.prototype.createOptionsTable = function (options, type)
self.getGuiUtils().addTab(self, {name: type, content: configurationDiv});
return Promise.all([self.bindUserGuiPreference({
jQueryObject: $(configurationTable),
event: 'length.dt',
preferenceName: 'admin-configuration-datatable-length',
defaultValue: '10',
getter: function () {
return $(configurationTable).DataTable().page.len() + '';
},
setter: function (value) {
return $(configurationTable).DataTable().page.len(value).draw();
}
return Promise.all([self.bindDataTablePageLengthToUserPreference({
element: configurationTable,
preferenceName: 'admin-configuration-datatable-length'
}), self.bindUserGuiPreference({
jQueryObject: $(configurationTable),
event: 'order.dt',
......
......@@ -90,17 +90,9 @@ GenomeAdminPanel.prototype._createGui = function () {
}],
order: [[1, "asc"], [4, "asc"]]
});
self.bindUserGuiPreference({
jQueryObject: $(genomesTable),
event: 'length.dt',
preferenceName: 'admin-genome-datatable-length',
defaultValue: '10',
getter: function () {
return $(genomesTable).DataTable().page.len() + '';
},
setter: function (value) {
return $(genomesTable).DataTable().page.len(value).draw();
}
self.bindDataTablePageLengthToUserPreference({
element: genomesTable,
preferenceName: 'admin-genome-datatable-length'
});
$(genomesTable).on("click", "[name='removeGenome']", function () {
......
......@@ -142,22 +142,14 @@ MapsAdminPanel.prototype._createProjectTableRow = function () {
}, {
title: 'Remove'
}],
order: [[ 0, "asc" ]],
order: [[0, "asc"]],
columnDefs: [
{"orderable": false, "targets": [7, 8]}
]
});
self.bindUserGuiPreference({
jQueryObject: $(projectsTable),
event: 'length.dt',
preferenceName: 'admin-projects-datatable-length',
defaultValue: '10',
getter: function () {
return $(projectsTable).DataTable().page.len() + '';
},
setter: function (value) {
return $(projectsTable).DataTable().page.len(value).draw();
}
self.bindDataTablePageLengthToUserPreference({
element: projectsTable,
preferenceName: 'admin-projects-datatable-length'
});
$(projectsTable).on("click", "[name='removeProject']", function () {
......@@ -191,7 +183,7 @@ MapsAdminPanel.prototype._createProjectTableRow = function () {
*/
MapsAdminPanel.prototype.init = function () {
var self = this;
return AbstractAdminPanel.prototype.init.call(self).then(function() {
return AbstractAdminPanel.prototype.init.call(self).then(function () {
return self.getServerConnector().getProjects();
}).then(function (projects) {
return self.setProjects(projects);
......
......@@ -69,17 +69,9 @@ PluginAdminPanel.prototype._createGui = function () {
}],
order: [[1, "asc"]]
});
self.bindUserGuiPreference({
jQueryObject: $(pluginsTable),
event: 'length.dt',
preferenceName: 'admin-plugins-datatable-length',
defaultValue: '10',
getter: function () {
return $(pluginsTable).DataTable().page.len() + '';
},
setter: function (value) {
return $(pluginsTable).DataTable().page.len(value).draw();
}
self.bindDataTablePageLengthToUserPreference({
element: pluginsTable,
preferenceName: 'admin-plugins-datatable-length'
});
$(pluginsTable).on("click", "[name='removePlugin']", function () {
......
......@@ -137,17 +137,9 @@ UsersAdminPanel.prototype._createUsersTableRow = function () {
]
});
self.bindUserGuiPreference({
jQueryObject: $(usersTable),
event: 'length.dt',
preferenceName: 'admin-users-datatable-length',
defaultValue: '10',
getter: function () {
return $(usersTable).DataTable().page.len() + '';
},
setter: function (value) {
return $(usersTable).DataTable().page.len(value).draw();
}
self.bindDataTablePageLengthToUserPreference({
element: usersTable,
preferenceName: 'admin-users-datatable-length'
});
$(usersTable).on("click", "[name='removeUser']", function () {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment