Skip to content

Commit

Permalink
Merge 3780185 into a0fde64
Browse files Browse the repository at this point in the history
  • Loading branch information
thostetler committed Jun 25, 2018
2 parents a0fde64 + 3780185 commit 374b160
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 24 deletions.
2 changes: 2 additions & 0 deletions src/js/modules/orcid/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,8 @@ function (
var action = data.action;
var orcidApi = this.getBeeHive().getService('OrcidApi');
var oldOrcid = _.clone(data.model.get('orcid') || {});
var pubsub = this.getPubSub();
pubsub.publish(pubsub.CUSTOM_EVENT, 'orcid-action', action);

var handlers = {
'orcid-add': function (model) {
Expand Down
60 changes: 36 additions & 24 deletions src/js/widgets/navbar/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ define([
orcidFirstName: undefined,
orcidLastName: undefined,
//should it show hourly banner?
hourly: false
hourly: false,
timeout: 600000 // 10 minutes
}
}
});
Expand Down Expand Up @@ -90,25 +91,11 @@ define([
this.trigger("user-change-orcid-mode");
},

changeOrcidMode: function () {
var that = this;
//allow animation to run before rerendering
setTimeout(function () {

if (that.$(".orcid-mode").is(":checked")) {
that.model.set("orcidModeOn", true);
}
else {
that.model.set("orcidModeOn", false);
}

//need to explicitly trigger to widget that this has changed
//otherwise it will be ignored, since it can also be changed
//from outside
that.trigger("user-change-orcid-mode");

that.render();
}, 400);
changeOrcidMode: function (ev) {
var checked = _.isBoolean(ev) ? ev : ev && ev.currentTarget && ev.currentTarget.checked;
this.model.set('orcidModeOn', checked);
this.trigger('user-change-orcid-mode');
this.render();
},

onRender: function () {
Expand Down Expand Up @@ -156,19 +143,42 @@ define([

activate: function (beehive) {
this.setBeeHive(beehive);
_.bindAll(this, ["handleUserAnnouncement", "getOrcidUserInfo", "storeLatestPage"]);
_.bindAll(this, ["handleUserAnnouncement", "getOrcidUserInfo", "storeLatestPage", 'onCustomEvent']);
var pubsub = this.getPubSub();
pubsub.subscribe(pubsub.USER_ANNOUNCEMENT, this.handleUserAnnouncement);
pubsub.subscribe(pubsub.APP_STARTED, this.getOrcidUserInfo);
pubsub.subscribe(pubsub.NAVIGATE, this.storeLatestPage)
pubsub.subscribe(pubsub.NAVIGATE, this.storeLatestPage);
pubsub.subscribe(pubsub.CUSTOM_EVENT, this.onCustomEvent);
this.setInitialVals();
if (!this.model.get('timer')) {
this.resetOrcidTimer();
}
},

onCustomEvent: function (ev) {
if (ev === 'orcid-action') {
this.resetOrcidTimer();
}
},

storeLatestPage : function(page){
//to know whether to orcid redirect
this._latestPage = page;
},

resetOrcidTimer: function () {
var timer = this.model.get('timer');
var timeout = this.model.get('timeout');
if (timer) {
clearTimeout(timer);
}

// only start the timer if orcid mode is actually on
if (this.model.get('orcidModeOn')) {
timer = setTimeout(_.bind(this.toggleOrcidMode, this, false), timeout);
this.model.set('timer', timer);
}
},

viewEvents: {
//dealing with authentication/user
Expand Down Expand Up @@ -307,19 +317,21 @@ define([
//we don't want to respond to changes from pubsub or user object with this,
//only changes that the user has initiated using the navbar widget,
//otherwise things will be toggled incorrectly
toggleOrcidMode: function () {
toggleOrcidMode: function (val) {
var user = this.getBeeHive().getObject('User'),
orcidApi = this.getBeeHive().getService("OrcidApi");

var newVal = this.model.get("orcidModeOn");
var newVal = _.isBoolean(val) ? val : this.model.get("orcidModeOn");
user.setOrcidMode(newVal);
this.model.set('orcidModeOn', newVal);

if (newVal) {
//sign into orcid api if not signed in already
if (!orcidApi.hasAccess()) {
orcidApi.signIn();
}
}
this.resetOrcidTimer();
},

searchAuthor: function () {
Expand Down

0 comments on commit 374b160

Please sign in to comment.