challenges: lock down editing capabilities on certain task properties,

instead showing the challenge's properties (in case they change
challenge-side).This includes editing the tag name
This commit is contained in:
Tyler Renelle 2013-05-28 11:52:32 +01:00
parent 2666ebb1fc
commit 2fbff2a0bc
5 changed files with 56 additions and 19 deletions

View file

@ -40,7 +40,7 @@ module.exports.app = (appExports, model) ->
# Add challenge name as a tag for user
tags = user.get('tags')
unless tags and _.find(tags,{id: chal.id})
model.push('_user.tags', {id: chal.id, name: chal.name})
model.push '_user.tags', {id: chal.id, name: chal.name, challenge: true}
tags = {}; tags[chal.id] = true
# Add all challenge's tasks to user's tasks
@ -50,6 +50,7 @@ module.exports.app = (appExports, model) ->
_.each chal["#{type}s"], (task) ->
task.tags = tags
task.challenge = chal.id
task.group = {id: chal.group.id, type: chal.group.type}
model.push("_#{type}List", task)
true

View file

@ -101,4 +101,21 @@ module.exports.viewHelpers = (view) ->
#Tags
view.fn 'noTags', helpers.noTags
view.fn 'appliedTags', helpers.appliedTags
view.fn 'appliedTags', helpers.appliedTags
#Challenges
view.fn 'taskAttrFromChallenge', (task, attr) ->
[tid, gid, cid, tType, gType] = [task.id, task.group.id, task.challenge, task.type, task.group.type]
findAttr = (challenges) ->
challenge = _.find(challenges,{id:cid})
val = _.find(challenge["#{tType}s"],{id:tid})[attr]
if attr is 'priority'
val = switch val
when '!!!' then 'Hard'
when '!!' then 'Medium'
else 'Easy'
return val
if gType is 'party'
findAttr @model.get("_party.challenges")
else if gType is 'guild'
findAttr _.find(@model.get("_guilds"),{id:gid}).challenges

View file

@ -19,9 +19,8 @@ module.exports.app = (appExports, model) ->
# Don't add a blank task; 20/02/13 Added a check for undefined value, more at issue #463 -lancemanfv
return if /^(\s)*$/.test(text) || text == undefined
newTask = {id: model.id(), type: type, text: text, notes: '', value: 0, tags:{}}
isChallenge = e.at().path().indexOf('_challenge.new') != -1
newTask.tags = if isChallenge then {} else _.reduce user.get('filters'), ((memo,v,k) -> memo[k]=v if v;memo), {}
newTask = {id: model.id(), type, text, notes: '', value: 0}
newTask.tags = _.reduce user.get('filters'), ((memo,v,k) -> memo[k]=v if v; memo), {}
switch type
when 'habit'

View file

@ -9,7 +9,7 @@
</li>
{#each _user.tags as :tag}
<li class="{#if _user.filters[:tag.id]}active{/}" style='position:relative;'>
{#if _editingTags}
{#if and(_editingTags,not(:tag.challenge))}
<div class="input-append option-group tag-editing" >
<input class="input input-small option-content tag-editing-pill" type="text" value='{:tag.name}' />
<span class="add-on tag-editing-pill"><a class='pull-right' x-bind=click:filtersDeleteTag data-index="{$index}"><i class='icon-trash'></i></a></span>

View file

@ -175,11 +175,13 @@
<!-- edit -->
<a x-bind=click:toggleTaskEdit data-hide-id="{{:task.id}}-chart" data-toggle-id="{{:task.id}}-edit" rel=tooltip title="Edit"><i class="icon-pencil"></i></a>
<!-- challenges -->
{{#if :task.challenge}}<i class='icon-bullhorn' rel=tooltip title="Challenge Task"></i>{{/}}
<!-- delete -->
<a x-bind=click:del rel=tooltip title="Delete"><i class="icon-trash"></i></a>
{{#if :task.challenge}}
<i class='icon-bullhorn' rel=tooltip title="Challenge Task"></i>
{{else}}
<!-- delete -->
<a x-bind=click:del rel=tooltip title="Delete"><i class="icon-trash"></i></a>
{{/}}
<!-- chart -->
<!-- removing for now cuz it's broken -->
{#if :task.history}
<a x-bind=click:toggleChart data-toggle-id="{{:task.id}}-chart" data-hide-id="{{:task.id}}-edit" data-history-path="_user.tasks.{{:task.id}}.history" rel="tooltip" title="Progress"><i class="icon-signal"></i></a>
{/}
@ -231,7 +233,11 @@
<!-- main content -->
<p class="task-text">
{:task.text}
{{#if :task.challenge}}
{{taskAttrFromChallenge(:task,'text')}}
{{else}}
{:task.text}
{{/}}
</p>
<!-- edit/options dialog -->
@ -244,12 +250,19 @@
<form x-bind=submit:toggleTaskEdit data-toggle-id="{{:task.id}}-edit">
<!-- text & notes -->
<fieldset class="option-group">
<label class="option-title">Text</label><input class="option-content" type=text value={:task.text}>
<label class="option-title">Extra Notes</label><textarea class="option-content" rows=3>{:task.notes}</textarea>
{{#unless :task.challenge}}
<label class="option-title">Text</label><input class="option-content" type=text value={:task.text}>
{{/}}
<label class="option-title">Extra Notes</label>
{{#if :task.challenge}}
<textarea class="option-content" rows=3 disabled>{{taskAttrFromChallenge(:task,'notes')}}</textarea>
{{else}}
<textarea class="option-content" rows=3>{:task.notes}</textarea>
{{/}}
</fieldset>
<!-- if Habit, plus/minus command options -->
{#if equal(:task.type, 'habit')}
{#if and(equal(:task.type, 'habit'),not(:task.challenge))}
<fieldset class="option-group">
<legend class="option-title">Direction/Actions</legend>
<span class="task-checker action-plusminus select-toggle">
@ -304,11 +317,18 @@
<p x-bind="click:tasksToggleAdvanced" class="option-title mega">Advanced Options</p>
<fieldset class="option-group advanced-option visuallyhidden">
<legend class="option-title"><a class='priority-multiplier-help' href="https://trello.com/card/priority-multiplier/50e5d3684fe3a7266b0036d6/17" target="_blank"><i class='icon-question-sign'></i></a> Difficulty</legend>
<div class="task-controls tile-group priority-multiplier" data-id="{{:task.id}}">
<button type="button" class="task-action-btn tile {#if equal(:task.priority,'!')}active{/}{#unless :task.priority}active{/}" data-priority='!' x-bind=click:tasksSetPriority>Easy</button>
<button type="button" class="task-action-btn tile {#if equal(:task.priority,'!!')}active{/}" data-priority='!!' x-bind=click:tasksSetPriority>Medium</button>
<button type="button" class="task-action-btn tile {#if equal(:task.priority,'!!!')}active{/}" data-priority='!!!' x-bind=click:tasksSetPriority>Hard</button>
</div>
{{#if :task.challenge}}
<button disabled type="button" class="task-action-btn tile active">
{{taskAttrFromChallenge(:task,'priority')}}
</button>
{{else}}
<div class="task-controls tile-group priority-multiplier" data-id="{{:task.id}}">
<button type="button" class="task-action-btn tile {#if or(equal(:task.priority,'!'),not(:task.priority))}active{/}" data-priority='!' x-bind=click:tasksSetPriority>Easy</button>
<button type="button" class="task-action-btn tile {#if equal(:task.priority,'!!')}active{/}" data-priority='!!' x-bind=click:tasksSetPriority>Medium</button>
<button type="button" class="task-action-btn tile {#if equal(:task.priority,'!!!')}active{/}" data-priority='!!!' x-bind=click:tasksSetPriority>Hard</button>
</div>
{{/}}
{{#if equal(:task.type,'daily')}}
<legend class="option-title">Restore Streak</legend>