Implemented a javascript code style

This commit is contained in:
Stefan Zermatten
2015-04-22 12:44:25 +02:00
parent dce20375b5
commit fada0f5136
113 changed files with 1614 additions and 1650 deletions

View File

@@ -17,7 +17,7 @@ Template.featureDialog.events({
Template.featureDetails.helpers({
or: function(a, b){
return a ||b;
return a || b;
},
hasUses: function(){
return this.usesValue() > 0;
@@ -43,7 +43,7 @@ Template.featureDetails.events({
"change .enabledCheckbox": function(event){
var enabled = !this.enabled;
Features.update(this._id, {$set: {enabled: enabled}});
}
},
});
Template.featureEdit.onRendered(function(){
@@ -55,10 +55,10 @@ Template.featureEdit.helpers({
return _.isString(this.uses);
},
enabledSelection: function(){
if(!this.enabled) return "disabled";
if(this.alwaysEnabled) return "alwaysEnabled";
if (!this.enabled) return "disabled";
if (this.alwaysEnabled) return "alwaysEnabled";
return "enabled";
}
},
});
Template.featureEdit.events({
@@ -73,7 +73,7 @@ Template.featureEdit.events({
"change #limitUseCheck": function(event){
var currentUses = this.uses;
var featureId = this._id;
if( event.target.checked && !_.isString(currentUses) ){
if (event.target.checked && !_.isString(currentUses)){
Features.update(featureId, {$set: {uses: ""}}, {removeEmptyStrings: false});
} else if (!event.target.checked && _.isString(currentUses)){
Features.update(featureId, {$unset: {uses: ""}});
@@ -86,17 +86,18 @@ Template.featureEdit.events({
},
"core-select #enabledDropdown": function(event){
var detail = event.originalEvent.detail;
if(!detail.isSelected) return;
if (!detail.isSelected) return;
var value = detail.item.getAttribute("name");
var setter;
if(value === "enabled"){
if (value === "enabled"){
setter = {enabled: true, alwaysEnabled: false};
} else if (value === "disabled"){
setter = {enabled: false, alwaysEnabled: false};
} else{
} else {
setter = {enabled: true, alwaysEnabled: true};
}
if (setter.enabled === this.enabled && setter.alwaysEnabled === this.alwaysEnabled) return;
if (setter.enabled === this.enabled &&
setter.alwaysEnabled === this.alwaysEnabled) return;
Features.update(this._id, {$set: setter});
},
});

View File

@@ -19,7 +19,9 @@ Template.features.helpers({
return _.indexOf(_.keys(colorOptions), this.color);
},
attacks: function(){
return Attacks.find({charId: this._id, enabled: true}, {sort: {color: 1, name: 1}});
return Attacks.find(
{charId: this._id, enabled: true},
{sort: {color: 1, name: 1}});
},
canEnable: function(){
return !this.alwaysEnabled;
@@ -41,7 +43,7 @@ Template.features.events({
GlobalUI.setDetail({
template: "featureDialog",
data: {featureId: featureId, charId: this._id, startEditing: true},
heroId: featureId
heroId: featureId,
});
},
"tap #addAttackButton": function(event){
@@ -49,11 +51,11 @@ Template.features.events({
Attacks.insert({
charId: charId
}, function(error, id){
if(!error){
if (!error){
GlobalUI.setDetail({
template: "attackDialog",
data: {attackId: id, charId: charId},
heroId: id
heroId: id,
});
}
});
@@ -64,7 +66,7 @@ Template.features.events({
GlobalUI.setDetail({
template: "featureDialog",
data: {featureId: featureId, charId: charId},
heroId: featureId
heroId: featureId,
});
},
"tap .attack": function(event){
@@ -82,8 +84,13 @@ Template.features.events({
var charId = this._id;
GlobalUI.setDetail({
template: "textDialog",
data: {charId: charId, field: "proficiencies", title: "Proficiencies", color: "q"},
heroId: this._id + "proficiencies"
data: {
charId: charId,
field: "proficiencies",
title: "Proficiencies",
color: "q",
},
heroId: this._id + "proficiencies",
});
},
"tap .enabledCheckbox": function(event){
@@ -92,45 +99,48 @@ Template.features.events({
"change .enabledCheckbox": function(event){
var enabled = !this.enabled;
Features.update(this._id, {$set: {enabled: enabled}});
}
},
});
Template.resource.helpers({
cantIncrement: function(){
return !(this.char.attributeValue(this.name) < this.char.attributeBase(this.name));
var baseBigger = this.char.attributeValue(this.name) <
this.char.attributeBase(this.name);
return !baseBigger;
},
cantDecrement: function(){
return !(this.char.attributeValue(this.name) > 0);
var valuePositive = this.char.attributeValue(this.name) > 0;
return !valuePositive;
},
getColor: function(){
if(this.char.attributeValue(this.name) > 0){
if (this.char.attributeValue(this.name) > 0){
return this.color;
} else {
return "grey";
}
}
},
});
Template.resource.events({
"tap .resourceUp": function(event){
if(this.char.attributeValue(this.name) < this.char.attributeBase(this.name)){
if (this.char.attributeValue(this.name) < this.char.attributeBase(this.name)){
var modifier = {$inc: {}};
modifier.$inc[this.name + ".adjustment"] = 1;
Characters.update(this.char._id, modifier, {validate: false});
}
},
"tap .resourceDown": function(event){
if(this.char.attributeValue(this.name) > 0){
if (this.char.attributeValue(this.name) > 0){
var modifier = {$inc: {}};
modifier.$inc[this.name + ".adjustment"] = -1;
Characters.update(this.char._id, modifier, {validate: false});
}
},
"tap .containerRight": function (event, instance) {
"tap .containerRight": function(event, instance) {
GlobalUI.setDetail({
template: "attributeDialog",
data: {name: this.title, statName: this.name, charId: this.char._id},
heroId: this.char._id + this.name
heroId: this.char._id + this.name,
});
}
},
});