Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* Fix a bug with duplicate toolbars

* Make buttons update if the user's status updates
* Correct state change handling
  • Loading branch information...
commit fb6e0ff7a7eef88d2b988ea0ff7f47c20cc3593d 1 parent 4022883
Dmitry Demeshchuk authored
Showing with 31 additions and 26 deletions.
  1. +16 −15 wrike.com/approve.coffee
  2. +15 −11 wrike.com/approve.js
View
31 wrike.com/approve.coffee
@@ -94,28 +94,24 @@
elm.removeClass hidden
else
elm.addClass hidden
-
-
class WrikeTaskApprover
cfg: wrikeConstants.task
setTask: (task) ->
- if @task is task
- return
+ if @task isnt task
+ @title = $(@cfg.containerSelector).find('textarea')
+ @state = @stateFromTitle()
+
@task = task
- @title = $(@cfg.containerSelector).find('textarea')
- @state = @stateFromTitle()
- # Have to remove the toolbar as view init event is being emmitted
- # multiple times from the stream view
- if $(@cfg.taistToolbarId).length
- return
- originalToolbar = $ @cfg.toolbarSelector
- @toolbar = originalToolbar.clone()
- @toolbar.attr 'id', @cfg.taistToolbarId
+ if not $('#' + @cfg.taistToolbarId).length
+ originalToolbar = $ @cfg.toolbarSelector
+ @toolbar = originalToolbar.clone()
+ @toolbar.attr 'id', @cfg.taistToolbarId
+ originalToolbar.after @toolbar
+
@toolbar.empty()
- originalToolbar.after @toolbar
roles = taistWrike.myTaskRoles(task)
if roles.owner and states[@state].owner or roles.author and states[@state].author
@@ -176,6 +172,11 @@
return
approver.setTask task
+ taistWrike.onTaskChange (task) ->
+ if not task
+ return
+ approver.setTask task
+
$(wrikeConstants.filters.streamViewButtonSelector).on 'click', ->
filters.renderFlags()
filters.filterTasks()
@@ -216,6 +217,6 @@
callback currentTask, currentTaskView
onTaskChange: (callback) ->
- utils.aspect.after Wrike.Task, 'getChanges', (-> callback @)
+ utils.aspect.after $wrike.record.Base.prototype, 'getChanges', (-> callback @)
{start}
View
26 wrike.com/approve.js
@@ -121,20 +121,18 @@
WrikeTaskApprover.prototype.setTask = function(task) {
var originalToolbar, roles;
- if (this.task === task) {
- return;
+ if (this.task !== task) {
+ this.title = $(this.cfg.containerSelector).find('textarea');
+ this.state = this.stateFromTitle();
}
this.task = task;
- this.title = $(this.cfg.containerSelector).find('textarea');
- this.state = this.stateFromTitle();
- if ($(this.cfg.taistToolbarId).length) {
- return;
+ if (!$('#' + this.cfg.taistToolbarId).length) {
+ originalToolbar = $(this.cfg.toolbarSelector);
+ this.toolbar = originalToolbar.clone();
+ this.toolbar.attr('id', this.cfg.taistToolbarId);
+ originalToolbar.after(this.toolbar);
}
- originalToolbar = $(this.cfg.toolbarSelector);
- this.toolbar = originalToolbar.clone();
- this.toolbar.attr('id', this.cfg.taistToolbarId);
this.toolbar.empty();
- originalToolbar.after(this.toolbar);
roles = taistWrike.myTaskRoles(task);
if (roles.owner && states[this.state].owner || roles.author && states[this.state].author) {
return this.renderControls();
@@ -219,6 +217,12 @@
}
return approver.setTask(task);
});
+ taistWrike.onTaskChange(function(task) {
+ if (!task) {
+ return;
+ }
+ return approver.setTask(task);
+ });
$(wrikeConstants.filters.streamViewButtonSelector).on('click', function() {
filters.renderFlags();
filters.filterTasks();
@@ -262,7 +266,7 @@
}
},
onTaskChange: function(callback) {
- return utils.aspect.after(Wrike.Task, 'getChanges', (function() {
+ return utils.aspect.after($wrike.record.Base.prototype, 'getChanges', (function() {
return callback(this);
}));
}
Please sign in to comment.
Something went wrong with that request. Please try again.