149 lines
4.9 KiB
JavaScript
149 lines
4.9 KiB
JavaScript
// Generated by CoffeeScript 1.6.3
|
|
(function() {
|
|
var helpers, _;
|
|
|
|
_ = require('lodash');
|
|
|
|
helpers = require('habitrpg-shared/script/helpers');
|
|
|
|
module.exports.app = function(appExports, model) {
|
|
var browser, challengeDiscard, user;
|
|
browser = require('./browser');
|
|
user = model.at('_user');
|
|
$('#profile-challenges-tab-link').on('show', function(e) {
|
|
return _.each(model.get('groups'), function(g) {
|
|
return _.each(g.challenges, function(chal) {
|
|
return _.each(['habit', 'daily', 'todo'], function(type) {
|
|
return _.each(chal["" + type + "s"], function(task) {
|
|
return _.each(chal.users, function(member) {
|
|
var chart, data, history, options, _ref, _ref1;
|
|
if ((history = member != null ? (_ref = member["" + type + "s"]) != null ? (_ref1 = _ref[task.id]) != null ? _ref1.history : void 0 : void 0 : void 0) && !!history) {
|
|
data = google.visualization.arrayToDataTable(_.map(history, function(h) {
|
|
return [h.date, h.value];
|
|
}));
|
|
options = {
|
|
backgroundColor: {
|
|
fill: 'transparent'
|
|
},
|
|
width: 150,
|
|
height: 50,
|
|
chartArea: {
|
|
width: '80%',
|
|
height: '80%'
|
|
},
|
|
axisTitlePosition: 'none',
|
|
legend: {
|
|
position: 'bottom'
|
|
},
|
|
hAxis: {
|
|
gridlines: {
|
|
color: 'transparent'
|
|
}
|
|
},
|
|
vAxis: {
|
|
gridlines: {
|
|
color: 'transparent'
|
|
}
|
|
}
|
|
};
|
|
chart = new google.visualization.LineChart($(".challenge-" + chal.id + "-member-" + member.id + "-history-" + task.id)[0]);
|
|
return chart.draw(data, options);
|
|
}
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
appExports.challengeCreate = function(e, el) {
|
|
var gid, type, _ref;
|
|
_ref = [$(el).attr('data-type'), $(el).attr('data-gid')], type = _ref[0], gid = _ref[1];
|
|
return model.set('_challenge.new', {
|
|
name: '',
|
|
habits: [],
|
|
dailys: [],
|
|
todos: [],
|
|
rewards: [],
|
|
id: model.id(),
|
|
uid: user.get('id'),
|
|
user: helpers.username(model.get('_user.auth'), model.get('_user.profile.name')),
|
|
group: {
|
|
type: type,
|
|
id: gid
|
|
},
|
|
timestamp: +(new Date)
|
|
});
|
|
};
|
|
appExports.challengeSave = function() {
|
|
var gid;
|
|
gid = model.get('_challenge.new.group.id');
|
|
return model.unshift("groups." + gid + ".challenges", model.get('_challenge.new'), function() {
|
|
browser.growlNotification('Challenge Created', 'success');
|
|
return challengeDiscard();
|
|
});
|
|
};
|
|
appExports.toggleChallengeEdit = function(e, el) {
|
|
var path;
|
|
path = "_editing.challenges." + ($(el).attr('data-id'));
|
|
return model.set(path, !model.get(path));
|
|
};
|
|
appExports.challengeDiscard = challengeDiscard = function() {
|
|
return model.del('_challenge.new');
|
|
};
|
|
appExports.challengeSubscribe = function(e) {
|
|
var chal, tags, userChallenges;
|
|
chal = e.get();
|
|
tags = user.get('tags');
|
|
if (!(tags && _.find(tags, {
|
|
id: chal.id
|
|
}))) {
|
|
model.push('_user.tags', {
|
|
id: chal.id,
|
|
name: chal.name,
|
|
challenge: true
|
|
});
|
|
}
|
|
tags = {};
|
|
tags[chal.id] = true;
|
|
userChallenges = user.get('challenges');
|
|
if (!(userChallenges && (userChallenges.indexOf(chal.id) !== -1))) {
|
|
user.unshift('challenges', chal.id);
|
|
}
|
|
return _.each(['habit', 'daily', 'todo', 'reward'], function(type) {
|
|
return _.each(chal["" + type + "s"], function(task) {
|
|
task.tags = tags;
|
|
task.challenge = chal.id;
|
|
task.group = {
|
|
id: chal.group.id,
|
|
type: chal.group.type
|
|
};
|
|
model.push("_" + type + "List", task);
|
|
return true;
|
|
});
|
|
});
|
|
};
|
|
return appExports.challengeUnsubscribe = function(e) {
|
|
var chal, i, _ref;
|
|
chal = e.get();
|
|
i = (_ref = user.get('challenges')) != null ? _ref.indexOf(chal.id) : void 0;
|
|
if ((i != null) && i !== -1) {
|
|
user.remove("challenges." + i);
|
|
}
|
|
return _.each(['habit', 'daily', 'todo', 'reward'], function(type) {
|
|
return _.each(chal["" + type + "s"], function(task) {
|
|
model.remove("_" + type + "List", _.findIndex(model.get("_" + type + "List", {
|
|
id: task.id
|
|
})));
|
|
model.del("_user.tasks." + task.id);
|
|
return true;
|
|
});
|
|
});
|
|
};
|
|
};
|
|
|
|
}).call(this);
|
|
|
|
/*
|
|
//@ sourceMappingURL=challenges.map
|
|
*/
|