Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 57 additions & 1 deletion tools/htdocs/components/10_Masthead_Tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@

Ensembl.Panel.Masthead = Ensembl.Panel.Masthead.extend({

toolsJobStateKey: 'ensembl.hasToolsJobs',

constructor: function (id) {
this.base(id);

Ensembl.EventManager.register('toolsRefreshMasthead', this, this.refreshToolsTab);
},

init: function () {
this.base();

Expand All @@ -28,11 +36,57 @@ Ensembl.Panel.Masthead = Ensembl.Panel.Masthead.extend({
this.recentJobs = $.makeArray(this.elLk.toolsDropdown.find('li a').map(function(i, el) { return (el.href.match(/tl\=([a-z0-9_\-]+)/i) || []).pop() || null; }));
this.fetchURL ='/' + (Ensembl.species || 'Multi') + '/Ajax/tools_tab';

if (this.elLk.toolsTabs.length) {
if (this.elLk.toolsTabs.length && this.shouldFetchToolsTab()) {
this.fetchToolsTab();
}
},

shouldFetchToolsTab: function() {
// The species-scoped */Ajax/tools_tab request checks private ticket state in
// the tools DB, so only make it when this browser is likely to have jobs.
return this.hasToolsJobState() || this.hasRecentJobs() || this.hasCurrentToolsPage() || !!(Ensembl.coreParams && Ensembl.coreParams['tl']);
},

hasRecentJobs: function() {
return this.recentJobs && this.recentJobs.length;
},

hasCurrentToolsPage: function() {
return this.elLk.toolsTabs.filter('.final').length;
},

hasToolsJobState: function() {
try {
return window.localStorage && window.localStorage.getItem(this.toolsJobStateKey) === '1';
} catch(e) {
return false;
}
},

setToolsJobState: function(flag) {
// The ajax response confirms whether this browser still needs eager tools tab
// refreshes on non-Tools pages.
try {
if (window.localStorage) {
if (flag) {
window.localStorage.setItem(this.toolsJobStateKey, '1');
} else {
window.localStorage.removeItem(this.toolsJobStateKey);
}
}
} catch(e) {}
},

refreshToolsTab: function(force, hasJobs) {
if (typeof hasJobs === 'boolean') {
this.setToolsJobState(hasJobs);
}

if (this.elLk.toolsTabs.length && (force || this.shouldFetchToolsTab())) {
this.fetchToolsTab();
}
},

fetchToolsTab: function() {
var panel = this;

Expand All @@ -51,10 +105,12 @@ Ensembl.Panel.Masthead = Ensembl.Panel.Masthead.extend({
populateToolsTab: function(response) {

if (response.empty) {
this.setToolsJobState(false);

this.elLk.toolsTabs.find('a:not(:first-child)').remove().end().find('.dropdown').removeClass('dropdown');

} else {
this.setToolsJobState(true);

this.elLk.toolsTabs.filter(':not(.final)').addClass('final').find('a:first-child').html(response.caption).attr('href', response.url);
this.elLk.toolsDropdown.find('ul.recent').remove().end().find('h4').first().html('Recent jobs').after($('<ul>').append($.map(response.tools, function(details, tool) {
Expand Down
5 changes: 5 additions & 0 deletions tools/htdocs/components/11_ContentTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ Ensembl.Panel.ContentTools = Ensembl.Panel.Content.extend({
if (methodName in this) {
this[methodName].apply(this, json.panelMethod);
json.panelMethod.unshift(methodName);
// Save/delete responses use refresh(), so re-check the masthead job tab
// state after they change ticket ownership or remove jobs.
if (methodName === 'refresh') {
Ensembl.EventManager.trigger('toolsRefreshMasthead', true);
}
return 'method_applied';
}

Expand Down
3 changes: 3 additions & 0 deletions tools/htdocs/components/15_ToolsForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ Ensembl.Panel.ToolsForm = Ensembl.Panel.ContentTools.extend({
/*
* Method called once ticket is successfully submitted via AJAX
*/
// Set the tools-tab hint immediately so later non-Tools pages can show Jobs
// without probing */Ajax/tools_tab for users who never submit jobs.
Ensembl.EventManager.trigger('toolsRefreshMasthead', true, true);
Ensembl.EventManager.trigger('toolsRefreshActivitySummary', true, true, false);
this.toggleForm(false, true);
},
Expand Down
201 changes: 149 additions & 52 deletions users/htdocs/components/10_Masthead_Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,71 +27,168 @@ Ensembl.Panel.Masthead = Ensembl.Panel.Masthead.extend({
init: function () {
this.base();

this.elLk.accountHolder = this.el.find('div._account_holder');
this.elLk.accountHolder = this.el.find('div._account_holder');

this.accountsRefreshURL = '';
this.accountsBookmarkData = '';
this.accountsRefreshURL = '';
this.accountsBookmarkData = '';
this.accountsDropdownLoaded = false;
this.accountsDropdownLoading = false;
this.accountsDropdownCallbacks = [];

this.refreshAccountsDropdown();
this.bindAccountsDropdown();
},

refreshAccountsDropdown: function() {
cacheAccountsForm: function() {
var form = this.elLk.accountHolder.find('form');

if (form.length) {
this.accountsRefreshURL = form.attr('action');
this.accountsBookmarkData = form.serialize();
}
},

bindAccountsDropdown: function() {
var panel = this;

if (this.elLk.accountHolder.length && !this.elLk.accountHolder.find('._accounts_no_user').length) {

var hideDropdown = function(e) {
if (!e.which || e.which === 1) {
panel.toggleAccountsDropdown(false);
$(document).off('click', hideDropdown);

if (!this.elLk.accountHolder.length) {
return;
}

this.cacheAccountsForm();

this.elLk.accountLink = this.elLk.accountHolder.find('._accounts_link').off('.accountsDropdown').on({
'click.accountsDropdown': function(event) {
event.preventDefault();

if (!$(this).hasClass('selected')) {
event.stopPropagation();
panel.showAccountsDropdown();
}
},
'focus.accountsDropdown': function() {
panel.loadAccountsDropdown();
}
});

this.elLk.accountDropdown = this.elLk.accountHolder.find('._accounts_dropdown').off('.accountsDropdown').on({
'click.accountsDropdown': function(event) {
if (event.target.nodeName !== 'A' && event.target.parentNode.nodeName !== 'A') {
event.stopPropagation();
}
}

if (!this.accountsRefreshURL) {
var form = this.elLk.accountHolder.find('form');
this.accountsRefreshURL = form.attr('action');
this.accountsBookmarkData = form.serialize();
}).find('a').off('.accountsDropdown').on('click.accountsDropdown', function(e) {
panel.hideAccountsDropdown(e);
}).end();

this.accountsDropdownLoaded = this.elLk.accountDropdown.length && $.trim(this.elLk.accountDropdown.html()).length ? true : false;

this.elLk.accountHolder.find('._accounts_no_userdb').helptip().off('.accountsDropdown').on({
'click.accountsDropdown': function(event) {
event.preventDefault();
}

$.ajax({
'url': this.accountsRefreshURL,
'context': this,
'data': this.accountsBookmarkData,
'type': 'POST',
'success': function(html) {
});
},

loadAccountsDropdown: function(callback, force) {
if ($.isFunction(callback)) {
this.accountsDropdownCallbacks.push(callback);
}

if (!this.elLk.accountHolder.length || (!force && this.elLk.accountHolder.find('._accounts_no_user').length)) {
this.accountsDropdownCallbacks = [];
return;
}

if (this.accountsDropdownLoaded && !force) {
this.runAccountsDropdownCallbacks();
return;
}

if (this.accountsDropdownLoading) {
return;
}

// Keep /Ajax/accounts_dropdown off the initial page load. Normal use fetches
// it on first open; force is reserved for account modal updates.
this.cacheAccountsForm();

if (!this.accountsRefreshURL) {
this.accountsRefreshURL = '/Ajax/accounts_dropdown';
}

this.accountsDropdownLoading = true;

$.ajax({
'url': this.accountsRefreshURL,
'context': this,
'data': this.accountsBookmarkData,
'type': 'POST',
'success': function(html) {
var response = $('<div>').html(html);
var accountDropdown = response.find('._accounts_dropdown');

if (!force && accountDropdown.length && this.elLk.accountHolder.find('._accounts_link').length) {
this.elLk.accountHolder.find('._accounts_dropdown').replaceWith(accountDropdown);
} else {
this.elLk.accountHolder.html(html);
this.elLk.accountLink = this.el.find('._accounts_link').on({
'click': function(event) {
event.preventDefault();
if (!$(this).hasClass('selected')) {
event.stopPropagation();
panel.toggleAccountsDropdown(true);
$(document).on('click', hideDropdown);
}
}
});

this.elLk.accountDropdown = this.el.find('._accounts_dropdown').on({
'click': function(event) {
if (event.target.nodeName !== 'A' && event.target.parentNode.nodeName !== 'A') {
event.stopPropagation();
}
}
}).find('a').on('click', hideDropdown).end();

this.elLk.accountHolder.find('._accounts_no_userdb').helptip().on({
'click': function(event) {
event.preventDefault();
}
});

},
'dataType': 'html'
this.elLk.accountHolder.toggleClass('_logged_in', this.elLk.accountHolder.find('._accounts_link').length ? true : false);
}

this.bindAccountsDropdown();
this.runAccountsDropdownCallbacks();
},
'error': function() {
this.accountsDropdownCallbacks = [];
},
'complete': function() {
this.accountsDropdownLoading = false;
},
'dataType': 'html'
});
},

refreshAccountsDropdown: function(callback) {
this.loadAccountsDropdown($.isFunction(callback) ? callback : null, true);
},

runAccountsDropdownCallbacks: function() {
var callback;

while (this.accountsDropdownCallbacks.length) {
callback = this.accountsDropdownCallbacks.shift();
callback.call(this);
}
},

showAccountsDropdown: function() {
var panel = this;

if (!this.accountsDropdownLoaded) {
this.loadAccountsDropdown(function() {
panel.showAccountsDropdown();
});
return;
}

this.toggleAccountsDropdown(true);

$(document).off('click.accountsDropdown').on('click.accountsDropdown', function(e) {
panel.hideAccountsDropdown(e);
});
},


hideAccountsDropdown: function(e) {
if (!e || !e.which || e.which === 1) {
this.toggleAccountsDropdown(false);
$(document).off('click.accountsDropdown');
}
},

toggleAccountsDropdown: function(flag) {
if (!this.elLk.accountLink.length || !this.elLk.accountDropdown.length) {
return;
}

this.elLk.accountLink.toggleClass('selected', flag);
this.elLk.accountDropdown.toggle(flag);
if (flag && !this.elLk.accountDropdown.data('initiated')) {
Expand Down
Loading