Commit 2cc2a511 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

common code extracted to separate function

parent 4f3bb3e2
......@@ -9,9 +9,7 @@ var Panel = require('../Panel');
var UserPreferences = require('../../map/data/UserPreferences');
var GuiConnector = require('../../GuiConnector');
// noinspection JSUnusedLocalSymbols
var logger = require('../../logger');
// noinspection JSUnusedLocalSymbols
var Functions = require('../../Functions');
var Promise = require("bluebird");
......@@ -109,6 +107,36 @@ AbstractAdminPanel.prototype.bindDataTablePageLengthToUserPreference = function
})
};
/**
*
* @param {Object} param
* @param {HTMLElement} param.element
* @param {string} param.preferenceName
*/
AbstractAdminPanel.prototype.bindDataTableOrderToUserPreference = function (param) {
var jQueryObject = $(param.element);
return this.bindUserGuiPreference({
jQueryObject: jQueryObject,
event: 'order.dt',
preferenceName: param.preferenceName,
defaultValue: '0-asc',
getter: function () {
var order = jQueryObject.DataTable().order();
return order[0][0] + "-" + order[0][1];
},
setter: function (value) {
var tmp = value.split("-");
var column = parseInt(tmp[0]);
var order = tmp[1];
if (Functions.isInt(column) && (order === "asc" || order === "desc")) {
return jQueryObject.DataTable().order([column, order]).draw();
} else {
logger.warn("Invalid order: " + column + "; " + order);
}
}
})
};
/**
*
......
......@@ -144,25 +144,9 @@ ConfigurationAdminPanel.prototype.createOptionsTable = function (options, type)
return Promise.all([self.bindDataTablePageLengthToUserPreference({
element: configurationTable,
preferenceName: 'admin-configuration-datatable-length'
}), self.bindUserGuiPreference({
jQueryObject: $(configurationTable),
event: 'order.dt',
preferenceName: 'admin-configuration-' + type + '-datatable-order',
defaultValue: '0-asc',
getter: function () {
var order = $(configurationTable).DataTable().order();
return order[0][0] + "-" + order[0][1];
},
setter: function (value) {
var tmp = value.split("-");
var column = parseInt(tmp[0]);
var order = tmp[1];
if (Functions.isInt(column) && (order === "asc" || order === "desc")) {
return $(configurationTable).DataTable().order([column, order]).draw();
} else {
logger.warn("Invalid order: " + column + "; " + order);
}
}
}), self.bindDataTableOrderToUserPreference({
element: configurationTable,
preferenceName: 'admin-configuration-' + type + '-datatable-order'
})]);
};
......
......@@ -173,25 +173,9 @@ GenomeAdminPanel.prototype.init = function () {
}).then(function () {
var genomesTable = $("[name='genomeTable']", self.getElement())[0];
return self.bindUserGuiPreference({
jQueryObject: $(genomesTable),
event: 'order.dt',
preferenceName: 'admin-genome-datatable-order',
defaultValue: '0-asc',
getter: function () {
var order = $(genomesTable).DataTable().order();
return order[0][0] + "-" + order[0][1];
},
setter: function (value) {
var tmp = value.split("-");
var column = parseInt(tmp[0]);
var order = tmp[1];
if (Functions.isInt(column) && (order === "asc" || order === "desc")) {
return $(genomesTable).DataTable().order([column, order]).draw();
} else {
logger.warn("Invalid order: " + column + "; " + order);
}
}
return self.bindDataTableOrderToUserPreference({
element: genomesTable,
preferenceName: 'admin-genome-datatable-order'
});
});
};
......
......@@ -197,25 +197,9 @@ MapsAdminPanel.prototype.init = function () {
var projectsTable = $("[name='projectsTable']", self.getElement())[0];
return self.bindUserGuiPreference({
jQueryObject: $(projectsTable),
event: 'order.dt',
preferenceName: 'admin-projects-datatable-order',
defaultValue: '0-asc',
getter: function () {
var order = $(projectsTable).DataTable().order();
return order[0][0] + "-" + order[0][1];
},
setter: function (value) {
var tmp = value.split("-");
var column = parseInt(tmp[0]);
var order = tmp[1];
if (Functions.isInt(column) && (order === "asc" || order === "desc")) {
return $(projectsTable).DataTable().order([column, order]).draw();
} else {
logger.warn("Invalid order: " + column + "; " + order);
}
}
return self.bindDataTableOrderToUserPreference({
element: projectsTable,
preferenceName: 'admin-projects-datatable-order'
});
});
};
......
......@@ -145,25 +145,9 @@ PluginAdminPanel.prototype.init = function () {
}).then(function () {
var pluginsTable = $("[name='pluginsTable']", self.getElement())[0];
return self.bindUserGuiPreference({
jQueryObject: $(pluginsTable),
event: 'order.dt',
preferenceName: 'admin-plugins-datatable-order',
defaultValue: '0-asc',
getter: function () {
var order = $(pluginsTable).DataTable().order();
return order[0][0] + "-" + order[0][1];
},
setter: function (value) {
var tmp = value.split("-");
var column = parseInt(tmp[0]);
var order = tmp[1];
if (Functions.isInt(column) && (order === "asc" || order === "desc")) {
return $(pluginsTable).DataTable().order([column, order]).draw();
} else {
logger.warn("Invalid order: " + column + "; " + order);
}
}
return self.bindDataTableOrderToUserPreference({
element: pluginsTable,
preferenceName: 'admin-plugins-datatable-order'
});
});
};
......
......@@ -261,25 +261,9 @@ UsersAdminPanel.prototype.init = function () {
}).then(function () {
var usersTable = $("[name='usersTable']", self.getElement())[0];
return self.bindUserGuiPreference({
jQueryObject: $(usersTable),
event: 'order.dt',
preferenceName: 'admin-users-datatable-order',
defaultValue: '0-asc',
getter: function () {
var order = $(usersTable).DataTable().order();
return order[0][0] + "-" + order[0][1];
},
setter: function (value) {
var tmp = value.split("-");
var column = parseInt(tmp[0]);
var order = tmp[1];
if (Functions.isInt(column) && (order === "asc" || order === "desc")) {
return $(usersTable).DataTable().order([column, order]).draw();
} else {
logger.warn("Invalid order: " + column + "; " + order);
}
}
return self.bindDataTableOrderToUserPreference({
element: usersTable,
preferenceName: 'admin-users-datatable-order'
});
});
};
......
......@@ -282,6 +282,7 @@ describe('minerva global', function () {
});
describe('createAdmin', function () {
this.timeout(3000);
it('as admin', function () {
helper.loginAsAdmin();
var options = helper.createCustomMapOptions(null);
......
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