Skip to content

Commit

Permalink
Moved plugins to demo/plugins and refactored addresses plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
nodeminderjs committed May 12, 2014
1 parent 0da658a commit 2dfa648
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 36 deletions.
2 changes: 1 addition & 1 deletion demo/admin_cfg.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Admin.startup(function() {
'createdAt': 'Created'
},
plugins: {
'profile.addresses': AddressesPlugin
'profile.addresses': aspAddressesPlugin
}
});

Expand Down
2 changes: 2 additions & 0 deletions demo/plugins/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Plugins
=======
8 changes: 4 additions & 4 deletions demo/addresses.css → demo/plugins/addresses.css
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
.addressesPlugin {
.asp-addresses-plugin {
margin-bottom: 4px;
}

.blank-address {
.asp-blank-address {
display: none;
}

.address {
.asp-address {
margin-bottom: 10px;
}

.address .row {
.asp-address .row {
margin-bottom: 4px;
}
24 changes: 13 additions & 11 deletions demo/addresses.html → demo/plugins/addresses.html
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
<template name="addressesPlugin">
<div id="addressesPlugin">
<div class="blank-address">
{{> address}}
<template name="aspAddresses">
<div id="asp-addresses-plugin">
<div class="asp-blank-address">
{{> aspAddress}}
</div>
<div id="addresses">

<div id="asp-addresses">
{{#if value}}
{{#each value}}
{{> address}}
{{> aspAddress}}
{{/each}}
{{else}}
{{> address}}
{{> aspAddress}}
{{/if}}
</div>
<button type="button" class="btn btn-primary btn-xs new">New address</button>

<button type="button" class="btn btn-primary btn-xs asp-btn-new">New address</button>
</div>
</template>

<template name="address">
<div class="address">
<template name="aspAddress">
<div class="asp-address">
<div class="row">
<div class="col-xs-12">
<input class="form-control input-sm street1" type="text" value="{{street1}}" placeholder="Street Address 1">
Expand All @@ -42,7 +44,7 @@
<input class="form-control input-sm country" type="text" value="{{country}}" placeholder="Country">
</div>
<div class="col-xs-2">
<button type="button" class="btn btn-danger btn-xs pull-right del">Delete address</button>
<button type="button" class="btn btn-danger btn-xs pull-right asp-btn-del">Delete address</button>
</div>
</div>
</div>
Expand Down
35 changes: 17 additions & 18 deletions demo/addresses.js → demo/plugins/addresses.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* Addresses plugin
*/

AddressesPlugin = {
template: 'addressesPlugin',
getValue: function() {
aspAddressesPlugin = {
template: 'aspAddresses',

getValue: function(field) {
var value = [], obj;
$("#addresses").children().each(function() {
$("#asp-addresses").children().each(function() {
obj = {};
obj['street1'] = $(".street1", this).val().trim(); // 'this' is the current element in the loop
if (obj['street1']) {
Expand All @@ -18,30 +18,29 @@ AddressesPlugin = {
value.push(obj);
}
});
console.log(value);
return value;
}
}

if (Meteor.isClient) {
var newClick = function(e) {
e.preventDefault();
var address = $(".blank-address .address").clone().appendTo($("#addresses"));
$(".del", address).click(delClick);
}

var delClick = function(e) {
e.preventDefault();
$(e.target).parent().parent().parent().remove();
if ($("#addresses").children().length === 0)
if ($("#asp-addresses").children().length === 0)
newClick(e);
}

Template.addressesPlugin.events({
'click .new': newClick

var newClick = function(e) {
e.preventDefault();
var address = $(".asp-blank-address .asp-address").clone().appendTo($("#asp-addresses"));
$(".asp-btn-del", address).click(delClick);
}

Template.aspAddresses.events({
'click .asp-btn-new': newClick
});

Template.address.events({
'click .del': delClick
Template.aspAddress.events({
'click .asp-btn-del': delClick
});
}
2 changes: 0 additions & 2 deletions lib/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,6 @@ Meteor.methods({
// beforeSave event
if (collectionObj.beforeSave)
collectionObj.beforeSave(collectionName, editDoc, 'update');

console.log('category=', editDoc.category);

var count = collectionObj.collection.update({_id: _id}, {$set: editDoc});

Expand Down

0 comments on commit 2dfa648

Please sign in to comment.