Implemented container editing
This commit is contained in:
@@ -5,7 +5,27 @@ Containers = new Meteor.Collection("containers");
|
||||
Schemas.Container = new SimpleSchema({
|
||||
name: { type: String },
|
||||
charId: { type: String, regEx: SimpleSchema.RegEx.Id},
|
||||
isCarried: { type: Boolean }
|
||||
isCarried: { type: Boolean },
|
||||
weight: {type: Number, min: 0, defaultValue: 0, decimal: true},
|
||||
value: {type: Number, min: 0, defaultValue: 0, decimal: true},
|
||||
description:{type: String, optional: true}
|
||||
});
|
||||
|
||||
Containers.attachSchema(Schemas.Container);
|
||||
Containers.attachSchema(Schemas.Container);
|
||||
|
||||
Containers.helpers({
|
||||
totalValue: function(){
|
||||
var value = this.value;
|
||||
Items.find({container: this._id, equipped: false}, {fields: {quantity: 1, value: 1}}).forEach(function(item){
|
||||
value += item.totalValue();
|
||||
});
|
||||
return value;
|
||||
},
|
||||
totalWeight: function(){
|
||||
var weight = this.weight;
|
||||
Items.find({container: this._id, equipped: false}, {fields: {weight: 1, value: 1}}).forEach(function(item){
|
||||
weight += item.totalWeight();
|
||||
});
|
||||
return weight;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -3,7 +3,7 @@ Items = new Meteor.Collection('items');
|
||||
Schemas.Item = new SimpleSchema({
|
||||
name: {type: String, defaultValue: "New Item"},
|
||||
plural: {type: String, optional: true},
|
||||
description:{type: String, defaultValue: ""},
|
||||
description:{type: String, optional: true},
|
||||
container: {type: String, regEx: SimpleSchema.RegEx.Id}, //id of container it is normally stowed in
|
||||
charId: {type: String, regEx: SimpleSchema.RegEx.Id}, //id of owner
|
||||
quantity: {type: Number, min: 0, defaultValue: 1},
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<template name="containerDialog">
|
||||
{{#with container}}
|
||||
<!--Delete button-->
|
||||
<paper-menu-button>
|
||||
<paper-icon-button role="button" tabindex="0" icon="delete" aria-label="Delete Container" noink></paper-icon-button>
|
||||
<paper-dropdown class="dropdown">
|
||||
<paper-button id="deleteContainer">Delete Container</paper-button>
|
||||
<paper-button>Cancel</paper-button>
|
||||
</paper-dropdown>
|
||||
</paper-menu-button>
|
||||
|
||||
<div class="containerDialogWidth"></div>
|
||||
<!--Name and plural name-->
|
||||
<paper-input id="containerNameInput" label="Name" floatinglabel value={{name}}></paper-input>
|
||||
<!--Weight-->
|
||||
<paper-input-decorator label="Weight" floatinglabel>
|
||||
<input id="weightInput" type="number" value={{weight}}>
|
||||
</paper-input-decorator>
|
||||
<!--Value-->
|
||||
<paper-input-decorator label="Value" floatinglabel>
|
||||
<input id="valueInput" type="number" value={{value}}>
|
||||
</paper-input-decorator>
|
||||
<!--Description-->
|
||||
<paper-input-decorator label="Description" floatinglabel layout vertical>
|
||||
<paper-autogrow-textarea>
|
||||
<textarea id="containerDescriptionInput" placeholder aria-label="Description" value={{description}}></textarea>
|
||||
</paper-autogrow-textarea>
|
||||
</paper-input-decorator>
|
||||
{{/with}}
|
||||
<paper-button affirmative>Done</paper-button>
|
||||
</template>
|
||||
@@ -0,0 +1,41 @@
|
||||
Template.containerDialog.rendered = function(){
|
||||
var self = this;
|
||||
this.autorun(function(){
|
||||
var container = Containers.findOne(Template.currentData().containerId, {fields: {name: 1}});
|
||||
if(container) Session.set("global.ui.dialogHeader", container.name);
|
||||
})
|
||||
//after the dialog is built, open it
|
||||
_.defer(function(){GlobalUI.dialog.open()});
|
||||
}
|
||||
|
||||
Template.containerDialog.events({
|
||||
"tap #deleteContainer": function(){
|
||||
Containers.remove(this._id);
|
||||
GlobalUI.closeDialog()
|
||||
},
|
||||
//TODO clean up String -> num here so they don't need casting by Schema.clean
|
||||
//TODO validate input (integer, non-negative, etc) for these inputs and give validation errors
|
||||
"change #containerNameInput, input #containerNameInput": function(event){
|
||||
console.log("changed Nameinput")
|
||||
var name = Template.instance().find("#containerNameInput").value;
|
||||
Containers.update(this._id, {$set: {name: name}});
|
||||
},
|
||||
"change #weightInput, input #weightInput": function(event){
|
||||
var weight = Template.instance().find("#weightInput").value;
|
||||
Containers.update(this._id, {$set: {weight: weight}});
|
||||
},
|
||||
"change #valueInput, input #valueInput": function(event){
|
||||
var value = Template.instance().find("#valueInput").value;
|
||||
Containers.update(this._id, {$set: {value: value}});
|
||||
},
|
||||
"change #containerDescriptionInput": function(event){
|
||||
var description = Template.instance().find("#containerDescriptionInput").value;
|
||||
Containers.update(this._id, {$set: {description: description}});
|
||||
}
|
||||
});
|
||||
|
||||
Template.containerDialog.helpers({
|
||||
container: function(){
|
||||
return Containers.findOne(this.containerId);
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,3 @@
|
||||
.containerName {
|
||||
cursor: pointer;
|
||||
}
|
||||
@@ -3,7 +3,13 @@
|
||||
<div id="inventory" class="scroll-y" fit>
|
||||
<paper-shadow class="equipment card double">
|
||||
Armor:<br>
|
||||
<paper-item>{{#if armor}}{{armor.name}}{{else}}none{{/if}}</paper-item>
|
||||
{{#if armor}}
|
||||
{{#with armor}}
|
||||
<paper-item class="inventoryItem">{{name}}</paper-item>
|
||||
{{/with}}
|
||||
{{else}}
|
||||
<paper-item>none</paper-item>
|
||||
{{/if}}
|
||||
Equipment:<br>
|
||||
{{#each equipment}}
|
||||
<paper-item class="inventoryItem">
|
||||
@@ -14,7 +20,7 @@
|
||||
<div class="containers">
|
||||
{{#each containers}}
|
||||
<paper-shadow class="card">
|
||||
<h3>{{name}}</h3>
|
||||
<h2 class="containerName">{{name}}</h2>
|
||||
{{#each items ../_id _id}}
|
||||
<paper-item class="inventoryItem">
|
||||
{{#if gt1 quantity}}{{quantity}}{{/if}} {{pluralName}}
|
||||
|
||||
@@ -53,5 +53,12 @@ Template.inventory.events({
|
||||
data: {itemId: this._id, charId: this.charId},
|
||||
fullOnMobile: true
|
||||
});
|
||||
},
|
||||
"tap .containerName": function(event){
|
||||
GlobalUI.setDialog({
|
||||
template: "containerDialog",
|
||||
data: {containerId: this._id, charId: this.charId},
|
||||
fullOnMobile: true
|
||||
});
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user