Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: doubleyou/taist_addon_examples
base: b1ee5a47ba
...
head fork: doubleyou/taist_addon_examples
compare: 82c3fee935
  • 4 commits
  • 2 files changed
  • 0 commit comments
  • 2 contributors
Commits on Jan 23, 2014
Dmitry Demeshchuk Almost finished approvals (need a hash-related fix and some refactoring) 882c7ab
@abelousov abelousov Merge pull request #1 from doubleyou/wrike-fixes
Almost finished approvals (need a hash-related fix and some refactoring)
2c00be0
Commits on Jan 27, 2014
Dmitry Demeshchuk Some refactoring, finished approves 980b1af
Commits on Jan 28, 2014
Dmitry Demeshchuk A small syntax fix 82c3fee
Showing with 427 additions and 468 deletions.
  1. +219 −220 wrike.com/approve.coffee
  2. +208 −248 wrike.com/approve.js
View
439 wrike.com/approve.coffee
@@ -1,221 +1,220 @@
->
- utils = null
- buttonsContainer = null
-
- start = (utilities) ->
- utils = utilities
-
- wrikeUtils.onTaskViewRender render
-
-# renderFilterPanel()
-
- render = (task) ->
- if task?
- stateMachine = addStateMachine()
- stateMachine.task = task
- stateMachine.applyCurrentState()
-
- addStateMachine = ->
- stateMachine = new StateMachine()
- buttonsContainerClass = "taist-stateButtonsContainer"
- buttonsContainer = $ '.' + buttonsContainerClass
- if buttonsContainer.length is 0
- utils.log 'buttons container doesnot exist, creating new one'
- buttonsContainer = $ '<div class="#{buttonsContainerClass}"></div>'
- prevElement = $('.wspace-task-importance-button')
- prevElement.after buttonsContainer
- utils.log 'inserted buttons container: ', prevElement, buttonsContainer, buttonsContainer.parent()
- else
- utils.log('emptying buttons container: ', buttonsContainer)
- buttonsContainer.empty()
- utils.log('emptying result: ', buttonsContainer)
-
- for state in stateMachine.allStates
- do (state) ->
- button = createButton state, stateMachine
- buttonsContainer.append button
- state.button = button
-
- return stateMachine
-
- createButton = (state, stateMachine) ->
- button = $("<a class=\"wrike-button-base x-btn-noicon\" style=\"width: auto; float: left; margin-left: 15px;\">" + state.buttonCaption + "</a>")
- button.click ->
- stateMachine.changeState state
- return false
- return button
-
- renderFilterPanel = ->
- filterPanel = new WrikeFilterPanel 'Approval'
- for state in ApproveState.allStates
- filterCheckbox = new WrikeFilterCheckbox state.filterName, state.tagText
- filterPanel.addCheckbox filterCheckbox
- filterPanel.waitToRender()
-
- class StateMachine
- allStates: []
- _initialNextStateIds: "toApprove"
- task: null
-
- constructor: ->
- @allStates.push new ApproveState("toApprove", "To approve", "To approve", "[ToApprove] ", ["declined", "approved"], "responsible", null)
- @allStates.push new ApproveState("declined", "Decline", "Declined", "[Declined] ", ["toApprove"], "author", null)
- @allStates.push new ApproveState("approved", "Approve", "Approved", "[Approved] ", [], "responsible", "1")
-
- applyCurrentState: ->
- currentState = null
- for state in @allStates
- if state.isUsedBy @task
- currentState = state
-
- @_applyState currentState, false
-
- changeState: (state) -> @_applyState state, true
-
- _applyState: (newState, needUpdate) ->
- if needUpdate
- @_updateTaskWithState newState
-
- nextStateIds = newState?.nextStateIds ? @_initialNextStateIds
- for state in @allStates
- visible = nextStateIds.indexOf(state.id) >= 0 && (state.canBeSetOn @task)
- state.button.toggle visible
-
- _updateTaskWithState: (currentState) ->
- for state in @allStates
- state.removeFromTask @task
-
- currentState.addToTask @task
-
- @task.save()
-
-
- class ApproveState
- nextStateIds: null
- availableFor: null
- button: null
- constructor: (@id, @buttonCaption, @filterName, @tagText, @nextStateIds, @availableFor, @newTaskState) ->
-
- isUsedBy: (task) -> (task.get "title").indexOf(@tagText) >= 0
-
- canBeSetOn: (task) ->
- if @availableFor is "responsible"
- wrikeUtils.currentUserIsResponsibleForTask task
- else if @availableFor is "author"
- wrikeUtils.currentUserIsAuthor task
- else
- null
-
- addToTask: (task) ->
- task.set 'title', @tagText + (task.get 'title')
- if @newTaskState?
- task.set "state", @newTaskState
-
-
- removeFromTask: (task) -> task.set 'title', ((task.get 'title').replace @tagText, '')
-
- class WrikeFilterCheckbox
- constructor: (@caption, @tagText) ->
- @contents = $ """<div style="padding-left:10px;"></div>"""
- container = $ """<div class="x-form-check-wrap"></div>"""
-
- form = $ "<div></div>",
- class: "x-form-checkbox-inner"
-
- @checkbox = $ "<input>"
- type: "checkbox"
- autocomplete: "off"
- class: "x-form-checkbox x-form-field",
- click: =>
- form.toggleClass "x-form-check-checked"
- @updateQuery()
-
- label = $ "<label></label>",
- class: "x-form-cb-label"
- text: @caption
-
- form.append @checkbox
- container.append form, label
- @contents.append container
-
- updateQuery: ->
- query = Wrike.env.FILTERS.get 'text'
- if @checked()
- query.push @tagText
- else
- query = (text for text in query when text != @tagText)
- BUS.fireEvent 'list.filter.changed',
- text: query
-
- checked: -> @checkbox.is ":checked"
-
- class WrikeFilterPanel
- template: null
- checkboxContainer: null
- _parentClass: 'w2-folder-listview-filters-filterspane-body'
- _getParent: -> ($ '.' + @_parentClass)
- constructor: (title)->
- @contents = $("""<div class="w2-folder-listview-filters-filterpane">
- <div class="w2-folder-listview-filters-filterpane-title x-unselectable">#{title}</div>
- <div class="x-form-check-group x-column-layout-ct x-form-field w2-folder-listview-filters-filterpane-chgroup">
- <div class="x-column-inner" id="ext-gen1145" style="width: 170px;">
- <div class=" x-column" style="width: 170px;">
- <div class="x-form-item x-hide-label" tabindex="-1"></div>
- <div class="x-form-clear-left"></div>
- </div>
- </div>
- </div>
- </div>""")
- @checkboxContainer = @contents.find ".x-form-item"
-
- waitToRender: ->
- that = @
- utils.aspect.after Ext.Panel, "afterRender", ->
- if @bodyCssClass == that._parentClass
- that._render()
-
- @_render()
-
- _render: -> @_getParent().append @contents
-
- addCheckbox: (checkbox) -> @checkboxContainer.append checkbox.contents
-
- wrikeUtils =
- getCurrentUserId: -> w2.user.getUid()
-
- currentUserIsResponsibleForTask: (task) -> task.data["responsibleList"].indexOf(@getCurrentUserId()) >= 0
-
- currentUserIsAuthor: (task) -> (task.get 'author') is @getCurrentUserId()
-
- getCurrentTaskView: -> window.Ext.ComponentMgr.get ($('.w3-task-view').attr 'id')
-
- getCurrentTask: -> @getCurrentTaskView()?["record"]
-
- onTaskViewRender: (callback) ->
- listenerName = "beforesetrecord"
- listenersInPrototype = w2.task.View.prototype.xlisteners
-
- utils.aspect.after listenersInPrototype, listenerName, (view, task) ->
- if task?
- task.load (loadedTask) ->
- utils.log 'set task: ', loadedTask.data.title
- callback loadedTask, view
- else
- utils.log 'unset task'
- return callback null, view
-
- [currentTask, currentTaskView] = [@getCurrentTask(), @getCurrentTaskView()]
-
- if currentTask? and currentTaskView?
-
- #manually replace already initialized listener in existing view
- #better would be just to override it in prototype before any view is created - more early addon launch is required
- enhancedListener = listenersInPrototype[listenerName]
- currentViewListeners = currentTaskView.events[listenerName].listeners[0]
- currentViewListeners.fn = currentViewListeners.fireFn = enhancedListener
-
- callback currentTask, currentTaskView
-
- onTaskChange: (callback) -> utils.aspect.after Wrike.Task, "getChanges", (-> callback @)
-
- return {start}
+ utils = null
+ approver = null
+
+ states = {
+ 'initial': {
+ triggers: {
+ 'Send for approval': 'onApproval'
+ }
+ },
+ 'onApproval': {
+ triggers: {
+ 'Approve': 'accepted'
+ 'Decline': 'declined'
+ },
+ titleTag: 'To Approve'
+ author: true
+ },
+ 'accepted': {
+ titleTag: 'Approved'
+ owner: true
+ },
+ 'declined': {
+ triggers: {
+ 'Send for approval': 'onApproval'
+ },
+ titleTag: 'Declined'
+ owner: true
+ }
+ }
+
+ wrikeConstants = {
+ common: {
+ classHidden: 'wrike-taist-hidden'
+ hiddenClassCss: '<style> .wrike-taist-hidden {display: none;} </style>'
+ },
+ filters: {
+ flagTemplate: '<a class="wrike-button-checkbox x-btn-noicon" href="#"></a>'
+ taistFiltersContainerId: 'wrike-taist-approval-filters'
+ flagsOuterContainerSelector: '.type-selector'
+ flagsInnerContainerSelector: '.x-column'
+ flagCheckedClass: 'x-btn-pressed'
+ streamTaskSelector: '.stream-task-entry'
+ streamViewButtonSelector: '.wspace_header_buttonStreamView'
+ },
+ task: {
+ containerSelector: '.wspace-task-widgets-title-view'
+ toolbarSelector: '.wspace-task-settings-bar'
+ taistToolbarId: 'wrike-taist-toolbar'
+ buttonTemplate: '<a class="wspace-task-settings-button"></a>'
+ buttonHighlightClass: 'x-btn-over'
+ }
+ }
+
+ class WrikeTaskFilters
+ filter: 'All'
+
+ cfg: wrikeConstants.filters
+
+ renderFlags: ->
+ if $('#' + @cfg.taistFiltersContainerId).length
+ return
+ originalFlags = $ @cfg.flagsOuterContainerSelector
+ flags = originalFlags.clone()
+ flags.attr 'id', @cfg.taistFiltersContainerId
+ flagsContainer = flags.find(@cfg.flagsInnerContainerSelector)
+ flagsContainer.empty()
+ originalFlags.after flags
+ self = @
+ for _, state of states
+ flag = $(self.cfg.flagTemplate)
+ flag.text state.titleTag or 'All'
+ flagsContainer.append flag
+ if @filter is flag.text()
+ flag.addClass(self.cfg.flagCheckedClass)
+ flag.on 'click', ->
+ flagsContainer.find('a').
+ removeClass(self.cfg.flagCheckedClass)
+ $(@).addClass(self.cfg.flagCheckedClass)
+ self.filter = $(@).text()
+ self.filterTasks()
+ false
+
+ filterTasks: ->
+ hidden = wrikeConstants.common.classHidden
+ $(@cfg.streamTaskSelector).each (i, element) =>
+ elm = $ element
+ if @filter is 'All'
+ elm.removeClass hidden
+ else
+ taskTitle = elm.find('span').text()
+ if taskTitle.match '\\[' + @filter + '\\]'
+ elm.removeClass hidden
+ else
+ elm.addClass hidden
+
+
+
+ class WrikeTaskApprover
+ cfg: wrikeConstants.task
+
+ setTask: (task) ->
+ if @task is task
+ return
+ @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
+ @toolbar.empty()
+ originalToolbar.after @toolbar
+
+ roles = taistWrike.myTaskRoles(task)
+ if roles.owner and states[@state].owner or roles.author and states[@state].author
+ @renderControls()
+
+ stateFromTitle: ->
+ m = @title.val().match /^\[(.+)\].*/
+ if not m?[1]
+ return 'initial'
+ for stateName, state of states
+ if state.titleTag is m[1]
+ return stateName
+
+ renderControls: ->
+ cfg = @cfg
+ mOver = ->
+ $(@).addClass cfg.buttonHighlightClass
+ mOut = ->
+ $(@).removeClass cfg.buttonHighlightClass
+ for buttonTitle, nextState of states[@state].triggers
+ do(buttonTitle, nextState) =>
+ button = $(cfg.buttonTemplate)
+ button.text buttonTitle
+ button.hover mOver, mOut
+ button.on 'click', =>
+ @toolbar.empty()
+ @applyState nextState
+ @renderControls()
+ false
+ @toolbar.append button
+
+
+ applyState: (newState) ->
+ newPrefix = '[' + states[newState].titleTag + '] '
+ if @state is 'initial'
+ @title.val(newPrefix + @title.val())
+ else
+ @title.val(@title.val().replace(/^\[.+\]\s/, newPrefix))
+
+ # Sequence for auto-saving modified ticket title
+ @title.focus()
+ $.event.trigger {type: 'keypress', which: 13 }
+ @title.blur()
+
+ @state = newState
+
+ approver = new WrikeTaskApprover()
+ filters = new WrikeTaskFilters()
+
+ start = (utilities) ->
+ utils = utilities
+
+ style = $ wrikeConstants.common.hiddenClassCss
+ $('html > head').append(style)
+
+ taistWrike.onTaskViewRender (task) ->
+ if not task
+ return
+ approver.setTask task
+
+ $(wrikeConstants.filters.streamViewButtonSelector).on 'click', ->
+ filters.renderFlags()
+ filters.filterTasks()
+ false
+
+ if window.location.hash.match(/stream/)
+ filters.renderFlags()
+ filters.filterTasks()
+
+ taistWrike =
+ me: -> $wrike.user.getUid()
+
+ myTaskRoles: (task) ->
+ {
+ owner: task.data['responsibleList'].indexOf(@me()) >= 0
+ author: (task.get 'author') is @me()
+ }
+
+ onTaskViewRender: (callback) ->
+ listenerName = 'load'
+ listenersInPrototype = $wspace.task.View.prototype.xlisteners
+
+ utils.aspect.after listenersInPrototype, listenerName, (view, task) ->
+ if task?
+ task.load (loadedTask) ->
+ callback loadedTask, view
+ else
+ return callback null, view
+
+ currentTaskView = window.Ext.ComponentMgr.get ($('.wspace-task-view').attr 'id')
+ currentTask = currentTaskView?['record']
+
+ if currentTask? and currentTaskView?
+ enhancedListener = listenersInPrototype[listenerName]
+ currentViewListeners = currentTaskView.events[listenerName].listeners[0]
+ currentViewListeners.fn = currentViewListeners.fireFn = enhancedListener
+
+ callback currentTask, currentTaskView
+
+ onTaskChange: (callback) ->
+ utils.aspect.after Wrike.Task, 'getChanges', (-> callback @)
+
+ {start}
View
456 wrike.com/approve.js
@@ -1,298 +1,258 @@
-
+// Generated by CoffeeScript 1.6.3
(function() {
- var ApproveState, StateMachine, WrikeFilterCheckbox, WrikeFilterPanel, addStateMachine, buttonsContainer, createButton, render, renderFilterPanel, start, utils, wrikeUtils;
+ var WrikeTaskApprover, WrikeTaskFilters, approver, filters, start, states, taistWrike, utils, wrikeConstants;
utils = null;
- buttonsContainer = null;
- start = function(utilities) {
- utils = utilities;
- return wrikeUtils.onTaskViewRender(render);
- };
- render = function(task) {
- var stateMachine;
- if (task != null) {
- stateMachine = addStateMachine();
- stateMachine.task = task;
- return stateMachine.applyCurrentState();
- }
- };
- addStateMachine = function() {
- var buttonsContainerClass, prevElement, state, stateMachine, _fn, _i, _len, _ref;
- stateMachine = new StateMachine();
- buttonsContainerClass = "taist-stateButtonsContainer";
- buttonsContainer = $('.' + buttonsContainerClass);
- if (buttonsContainer.length === 0) {
- utils.log('buttons container doesnot exist, creating new one');
- buttonsContainer = $('<div class="#{buttonsContainerClass}"></div>');
- prevElement = $('.wspace-task-importance-button');
- prevElement.after(buttonsContainer);
- utils.log('inserted buttons container: ', prevElement, buttonsContainer, buttonsContainer.parent());
- } else {
- utils.log('emptying buttons container: ', buttonsContainer);
- buttonsContainer.empty();
- utils.log('emptying result: ', buttonsContainer);
- }
- _ref = stateMachine.allStates;
- _fn = function(state) {
- var button;
- button = createButton(state, stateMachine);
- buttonsContainer.append(button);
- return state.button = button;
- };
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
- state = _ref[_i];
- _fn(state);
+ approver = null;
+ states = {
+ 'initial': {
+ triggers: {
+ 'Send for approval': 'onApproval'
+ }
+ },
+ 'onApproval': {
+ triggers: {
+ 'Approve': 'accepted',
+ 'Decline': 'declined'
+ },
+ titleTag: 'To Approve',
+ author: true
+ },
+ 'accepted': {
+ titleTag: 'Approved',
+ owner: true
+ },
+ 'declined': {
+ triggers: {
+ 'Send for approval': 'onApproval'
+ },
+ titleTag: 'Declined',
+ owner: true
}
- return stateMachine;
- };
- createButton = function(state, stateMachine) {
- var button;
- button = $("<a class=\"wrike-button-base x-btn-noicon\" style=\"width: auto; float: left; margin-left: 15px;\">" + state.buttonCaption + "</a>");
- button.click(function() {
- stateMachine.changeState(state);
- return false;
- });
- return button;
};
- renderFilterPanel = function() {
- var filterCheckbox, filterPanel, state, _i, _len, _ref;
- filterPanel = new WrikeFilterPanel('Approval');
- _ref = ApproveState.allStates;
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
- state = _ref[_i];
- filterCheckbox = new WrikeFilterCheckbox(state.filterName, state.tagText);
- filterPanel.addCheckbox(filterCheckbox);
+ wrikeConstants = {
+ common: {
+ classHidden: 'wrike-taist-hidden',
+ hiddenClassCss: '<style> .wrike-taist-hidden {display: none;} </style>'
+ },
+ filters: {
+ flagTemplate: '<a class="wrike-button-checkbox x-btn-noicon" href="#"></a>',
+ taistFiltersContainerId: 'wrike-taist-approval-filters',
+ flagsOuterContainerSelector: '.type-selector',
+ flagsInnerContainerSelector: '.x-column',
+ flagCheckedClass: 'x-btn-pressed',
+ streamTaskSelector: '.stream-task-entry',
+ streamViewButtonSelector: '.wspace_header_buttonStreamView'
+ },
+ task: {
+ containerSelector: '.wspace-task-widgets-title-view',
+ toolbarSelector: '.wspace-task-settings-bar',
+ taistToolbarId: 'wrike-taist-toolbar',
+ buttonTemplate: '<a class="wspace-task-settings-button"></a>',
+ buttonHighlightClass: 'x-btn-over'
}
- return filterPanel.waitToRender();
};
- StateMachine = (function() {
+ WrikeTaskFilters = (function() {
+ function WrikeTaskFilters() {}
- StateMachine.prototype.allStates = [];
+ WrikeTaskFilters.prototype.filter = 'All';
- StateMachine.prototype._initialNextStateIds = "toApprove";
+ WrikeTaskFilters.prototype.cfg = wrikeConstants.filters;
- StateMachine.prototype.task = null;
-
- function StateMachine() {
- this.allStates.push(new ApproveState("toApprove", "To approve", "To approve", "[ToApprove] ", ["declined", "approved"], "responsible", null));
- this.allStates.push(new ApproveState("declined", "Decline", "Declined", "[Declined] ", ["toApprove"], "author", null));
- this.allStates.push(new ApproveState("approved", "Approve", "Approved", "[Approved] ", [], "responsible", "1"));
- }
-
- StateMachine.prototype.applyCurrentState = function() {
- var currentState, state, _i, _len, _ref;
- currentState = null;
- _ref = this.allStates;
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
- state = _ref[_i];
- if (state.isUsedBy(this.task)) currentState = state;
+ WrikeTaskFilters.prototype.renderFlags = function() {
+ var flag, flags, flagsContainer, originalFlags, self, state, _, _results;
+ if ($('#' + this.cfg.taistFiltersContainerId).length) {
+ return;
}
- return this._applyState(currentState, false);
- };
-
- StateMachine.prototype.changeState = function(state) {
- return this._applyState(state, true);
- };
-
- StateMachine.prototype._applyState = function(newState, needUpdate) {
- var nextStateIds, state, visible, _i, _len, _ref, _ref2, _results;
- if (needUpdate) this._updateTaskWithState(newState);
- nextStateIds = (_ref = newState != null ? newState.nextStateIds : void 0) != null ? _ref : this._initialNextStateIds;
- _ref2 = this.allStates;
+ originalFlags = $(this.cfg.flagsOuterContainerSelector);
+ flags = originalFlags.clone();
+ flags.attr('id', this.cfg.taistFiltersContainerId);
+ flagsContainer = flags.find(this.cfg.flagsInnerContainerSelector);
+ flagsContainer.empty();
+ originalFlags.after(flags);
+ self = this;
_results = [];
- for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
- state = _ref2[_i];
- visible = nextStateIds.indexOf(state.id) >= 0 && (state.canBeSetOn(this.task));
- _results.push(state.button.toggle(visible));
+ for (_ in states) {
+ state = states[_];
+ flag = $(self.cfg.flagTemplate);
+ flag.text(state.titleTag || 'All');
+ flagsContainer.append(flag);
+ if (this.filter === flag.text()) {
+ flag.addClass(self.cfg.flagCheckedClass);
+ }
+ _results.push(flag.on('click', function() {
+ flagsContainer.find('a').removeClass(self.cfg.flagCheckedClass);
+ $(this).addClass(self.cfg.flagCheckedClass);
+ self.filter = $(this).text();
+ self.filterTasks();
+ return false;
+ }));
}
return _results;
};
- StateMachine.prototype._updateTaskWithState = function(currentState) {
- var state, _i, _len, _ref;
- _ref = this.allStates;
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
- state = _ref[_i];
- state.removeFromTask(this.task);
- }
- currentState.addToTask(this.task);
- return this.task.save();
+ WrikeTaskFilters.prototype.filterTasks = function() {
+ var hidden,
+ _this = this;
+ hidden = wrikeConstants.common.classHidden;
+ return $(this.cfg.streamTaskSelector).each(function(i, element) {
+ var elm, taskTitle;
+ elm = $(element);
+ if (_this.filter === 'All') {
+ return elm.removeClass(hidden);
+ } else {
+ taskTitle = elm.find('span').text();
+ if (taskTitle.match('\\[' + _this.filter + '\\]')) {
+ return elm.removeClass(hidden);
+ } else {
+ return elm.addClass(hidden);
+ }
+ }
+ });
};
- return StateMachine;
+ return WrikeTaskFilters;
})();
- ApproveState = (function() {
-
- ApproveState.prototype.nextStateIds = null;
-
- ApproveState.prototype.availableFor = null;
+ WrikeTaskApprover = (function() {
+ function WrikeTaskApprover() {}
- ApproveState.prototype.button = null;
+ WrikeTaskApprover.prototype.cfg = wrikeConstants.task;
- function ApproveState(id, buttonCaption, filterName, tagText, nextStateIds, availableFor, newTaskState) {
- this.id = id;
- this.buttonCaption = buttonCaption;
- this.filterName = filterName;
- this.tagText = tagText;
- this.nextStateIds = nextStateIds;
- this.availableFor = availableFor;
- this.newTaskState = newTaskState;
- }
-
- ApproveState.prototype.isUsedBy = function(task) {
- return (task.get("title")).indexOf(this.tagText) >= 0;
- };
-
- ApproveState.prototype.canBeSetOn = function(task) {
- if (this.availableFor === "responsible") {
- return wrikeUtils.currentUserIsResponsibleForTask(task);
- } else if (this.availableFor === "author") {
- return wrikeUtils.currentUserIsAuthor(task);
- } else {
- return null;
+ WrikeTaskApprover.prototype.setTask = function(task) {
+ var originalToolbar, roles;
+ if (this.task === task) {
+ return;
+ }
+ this.task = task;
+ this.title = $(this.cfg.containerSelector).find('textarea');
+ this.state = this.stateFromTitle();
+ if ($(this.cfg.taistToolbarId).length) {
+ return;
+ }
+ 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();
}
};
- ApproveState.prototype.addToTask = function(task) {
- task.set('title', this.tagText + (task.get('title')));
- if (this.newTaskState != null) return task.set("state", this.newTaskState);
- };
-
- ApproveState.prototype.removeFromTask = function(task) {
- return task.set('title', (task.get('title')).replace(this.tagText, ''));
+ WrikeTaskApprover.prototype.stateFromTitle = function() {
+ var m, state, stateName;
+ m = this.title.val().match(/^\[(.+)\].*/);
+ if (!(m != null ? m[1] : void 0)) {
+ return 'initial';
+ }
+ for (stateName in states) {
+ state = states[stateName];
+ if (state.titleTag === m[1]) {
+ return stateName;
+ }
+ }
};
- return ApproveState;
-
- })();
- WrikeFilterCheckbox = (function() {
-
- function WrikeFilterCheckbox(caption, tagText) {
- var container, form, label,
+ WrikeTaskApprover.prototype.renderControls = function() {
+ var buttonTitle, cfg, mOut, mOver, nextState, _ref, _results,
_this = this;
- this.caption = caption;
- this.tagText = tagText;
- this.contents = $("<div style=\"padding-left:10px;\"></div>");
- container = $("<div class=\"x-form-check-wrap\"></div>");
- form = $("<div></div>", {
- "class": "x-form-checkbox-inner"
- });
- this.checkbox = $("<input>", {
- type: "checkbox",
- autocomplete: "off",
- "class": "x-form-checkbox x-form-field",
- click: function() {
- form.toggleClass("x-form-check-checked");
- return _this.updateQuery();
- }
- });
- label = $("<label></label>", {
- "class": "x-form-cb-label",
- text: this.caption
- });
- form.append(this.checkbox);
- container.append(form, label);
- this.contents.append(container);
- }
+ cfg = this.cfg;
+ mOver = function() {
+ return $(this).addClass(cfg.buttonHighlightClass);
+ };
+ mOut = function() {
+ return $(this).removeClass(cfg.buttonHighlightClass);
+ };
+ _ref = states[this.state].triggers;
+ _results = [];
+ for (buttonTitle in _ref) {
+ nextState = _ref[buttonTitle];
+ _results.push((function(buttonTitle, nextState) {
+ var button;
+ button = $(cfg.buttonTemplate);
+ button.text(buttonTitle);
+ button.hover(mOver, mOut);
+ button.on('click', function() {
+ _this.toolbar.empty();
+ _this.applyState(nextState);
+ _this.renderControls();
+ return false;
+ });
+ return _this.toolbar.append(button);
+ })(buttonTitle, nextState));
+ }
+ return _results;
+ };
- WrikeFilterCheckbox.prototype.updateQuery = function() {
- var query, text;
- query = Wrike.env.FILTERS.get('text');
- if (this.checked()) {
- query.push(this.tagText);
+ WrikeTaskApprover.prototype.applyState = function(newState) {
+ var newPrefix;
+ newPrefix = '[' + states[newState].titleTag + '] ';
+ if (this.state === 'initial') {
+ this.title.val(newPrefix + this.title.val());
} else {
- query = (function() {
- var _i, _len, _results;
- _results = [];
- for (_i = 0, _len = query.length; _i < _len; _i++) {
- text = query[_i];
- if (text !== this.tagText) _results.push(text);
- }
- return _results;
- }).call(this);
+ this.title.val(this.title.val().replace(/^\[.+\]\s/, newPrefix));
}
- return BUS.fireEvent('list.filter.changed', {
- text: query
+ this.title.focus();
+ $.event.trigger({
+ type: 'keypress',
+ which: 13
});
+ this.title.blur();
+ return this.state = newState;
};
- WrikeFilterCheckbox.prototype.checked = function() {
- return this.checkbox.is(":checked");
- };
-
- return WrikeFilterCheckbox;
+ return WrikeTaskApprover;
})();
- WrikeFilterPanel = (function() {
-
- WrikeFilterPanel.prototype.template = null;
-
- WrikeFilterPanel.prototype.checkboxContainer = null;
-
- WrikeFilterPanel.prototype._parentClass = 'w2-folder-listview-filters-filterspane-body';
-
- WrikeFilterPanel.prototype._getParent = function() {
- return $('.' + this._parentClass);
- };
-
- function WrikeFilterPanel(title) {
- this.contents = $("<div class=\"w2-folder-listview-filters-filterpane\">\n <div class=\"w2-folder-listview-filters-filterpane-title x-unselectable\">" + title + "</div>\n <div class=\"x-form-check-group x-column-layout-ct x-form-field w2-folder-listview-filters-filterpane-chgroup\">\n <div class=\"x-column-inner\" id=\"ext-gen1145\" style=\"width: 170px;\">\n <div class=\" x-column\" style=\"width: 170px;\">\n <div class=\"x-form-item x-hide-label\" tabindex=\"-1\"></div>\n <div class=\"x-form-clear-left\"></div>\n </div>\n </div>\n </div>\n</div>");
- this.checkboxContainer = this.contents.find(".x-form-item");
+ approver = new WrikeTaskApprover();
+ filters = new WrikeTaskFilters();
+ start = function(utilities) {
+ var style;
+ utils = utilities;
+ style = $(wrikeConstants.common.hiddenClassCss);
+ $('html > head').append(style);
+ taistWrike.onTaskViewRender(function(task) {
+ if (!task) {
+ return;
+ }
+ return approver.setTask(task);
+ });
+ $(wrikeConstants.filters.streamViewButtonSelector).on('click', function() {
+ filters.renderFlags();
+ filters.filterTasks();
+ return false;
+ });
+ if (window.location.hash.match(/stream/)) {
+ filters.renderFlags();
+ return filters.filterTasks();
}
-
- WrikeFilterPanel.prototype.waitToRender = function() {
- var that;
- that = this;
- utils.aspect.after(Ext.Panel, "afterRender", function() {
- if (this.bodyCssClass === that._parentClass) return that._render();
- });
- return this._render();
- };
-
- WrikeFilterPanel.prototype._render = function() {
- return this._getParent().append(this.contents);
- };
-
- WrikeFilterPanel.prototype.addCheckbox = function(checkbox) {
- return this.checkboxContainer.append(checkbox.contents);
- };
-
- return WrikeFilterPanel;
-
- })();
- wrikeUtils = {
- getCurrentUserId: function() {
- return w2.user.getUid();
- },
- currentUserIsResponsibleForTask: function(task) {
- return task.data["responsibleList"].indexOf(this.getCurrentUserId()) >= 0;
- },
- currentUserIsAuthor: function(task) {
- return (task.get('author')) === this.getCurrentUserId();
- },
- getCurrentTaskView: function() {
- return window.Ext.ComponentMgr.get($('.w3-task-view').attr('id'));
+ };
+ taistWrike = {
+ me: function() {
+ return $wrike.user.getUid();
},
- getCurrentTask: function() {
- var _ref;
- return (_ref = this.getCurrentTaskView()) != null ? _ref["record"] : void 0;
+ myTaskRoles: function(task) {
+ return {
+ owner: task.data['responsibleList'].indexOf(this.me()) >= 0,
+ author: (task.get('author')) === this.me()
+ };
},
onTaskViewRender: function(callback) {
- var currentTask, currentTaskView, currentViewListeners, enhancedListener, listenerName, listenersInPrototype, _ref;
- listenerName = "beforesetrecord";
- listenersInPrototype = w2.task.View.prototype.xlisteners;
+ var currentTask, currentTaskView, currentViewListeners, enhancedListener, listenerName, listenersInPrototype;
+ listenerName = 'load';
+ listenersInPrototype = $wspace.task.View.prototype.xlisteners;
utils.aspect.after(listenersInPrototype, listenerName, function(view, task) {
if (task != null) {
return task.load(function(loadedTask) {
- utils.log('set task: ', loadedTask.data.title);
return callback(loadedTask, view);
});
} else {
- utils.log('unset task');
return callback(null, view);
}
});
- _ref = [this.getCurrentTask(), this.getCurrentTaskView()], currentTask = _ref[0], currentTaskView = _ref[1];
+ currentTaskView = window.Ext.ComponentMgr.get($('.wspace-task-view').attr('id'));
+ currentTask = currentTaskView != null ? currentTaskView['record'] : void 0;
if ((currentTask != null) && (currentTaskView != null)) {
enhancedListener = listenersInPrototype[listenerName];
currentViewListeners = currentTaskView.events[listenerName].listeners[0];
@@ -301,7 +261,7 @@
}
},
onTaskChange: function(callback) {
- return utils.aspect.after(Wrike.Task, "getChanges", (function() {
+ return utils.aspect.after(Wrike.Task, 'getChanges', (function() {
return callback(this);
}));
}

No commit comments for this range

Something went wrong with that request. Please try again.