mirror of
https://github.com/donl/meteor-ionic.git
synced 2026-05-29 06:12:31 -06:00
dynamic class names, pull delete into ionList
This commit is contained in:
parent
e5fb0b1412
commit
7cd20914e9
3 changed files with 87 additions and 84 deletions
|
|
@ -30,6 +30,10 @@ Template.ionItem.helpers({
|
|||
classes.push('item-button-left');
|
||||
}
|
||||
|
||||
if(Session.get('ionSortable')){
|
||||
classes.push('item-complex', 'item-left-editable');
|
||||
}
|
||||
|
||||
if (this.buttonRight) {
|
||||
classes.push('item-button-right');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,94 +1,103 @@
|
|||
Template.ionList.helpers({
|
||||
classes: function() {
|
||||
var classes = ['list'];
|
||||
classes: function() {
|
||||
var classes = ['list'];
|
||||
|
||||
if (this.class) {
|
||||
var customClasses = this.class.split(' ');
|
||||
_(customClasses).each(function(customClass) {
|
||||
classes.push(customClass);
|
||||
});
|
||||
}
|
||||
|
||||
if (this.rightEdit) {
|
||||
classes.push('list-right-editing');
|
||||
}
|
||||
|
||||
if (this.leftEdit) {
|
||||
classes.push('list-left-editing');
|
||||
}
|
||||
|
||||
return classes.join(' ');
|
||||
if (this.class) {
|
||||
var customClasses = this.class.split(' ');
|
||||
_(customClasses).each(function(customClass) {
|
||||
classes.push(customClass);
|
||||
});
|
||||
}
|
||||
|
||||
if (this.rightEdit) {
|
||||
classes.push('list-right-editing');
|
||||
}
|
||||
|
||||
if (this.leftEdit) {
|
||||
classes.push('list-left-editing');
|
||||
}
|
||||
|
||||
return classes.join(' ');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Template.ionList.rendered = function() {
|
||||
|
||||
if (this.data && this.data.ionSortable){
|
||||
Session.set("ionSortable", true );
|
||||
var list = this.$('.list')[0];
|
||||
new Slip(list);
|
||||
//TODO: ensure not creating a slip list if unnecessary
|
||||
};
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
Template.ionList.events({
|
||||
'slip:swipe .list': function(e, template) {
|
||||
e.preventDefault();
|
||||
},
|
||||
'slip:beforereorder .list': function(e, template) {
|
||||
if (e.originalEvent.target.className.indexOf('instant') == -1) {
|
||||
e.preventDefault();
|
||||
Template.ionList.events({
|
||||
'click .item-delete' : function(e, template){
|
||||
e.preventDefault();
|
||||
|
||||
target = $(e.target).closest('.item').get(0);
|
||||
|
||||
targetData = Blaze.getData(target.getElementsByClassName('item-content')[0])._id || undefined;
|
||||
|
||||
template.data.ionSortable.find({}).forEach(function(item, i) {
|
||||
if (item._id === targetData) {
|
||||
template.data.ionSortable._collection.remove({
|
||||
_id: item._id
|
||||
}, function(error, result) { });
|
||||
}
|
||||
},
|
||||
'slip:beforeswipe .list': function(e, template) {
|
||||
e.preventDefault();
|
||||
},
|
||||
'slip:beforewait .list': function(e, template) {
|
||||
e.preventDefault();
|
||||
},
|
||||
'slip:afterswipe .list': function(e, template) {
|
||||
e.preventDefault();
|
||||
},
|
||||
'slip:reorder .list': function(e, template) {
|
||||
spliceIndex = e.originalEvent.detail.spliceIndex
|
||||
originalIndex = e.originalEvent.detail.originalIndex
|
||||
});
|
||||
},
|
||||
'slip:swipe .list, slip:beforeswipe .list, slip:beforewait .list, slip:afterswipe .list': function(e, template) {
|
||||
e.preventDefault();
|
||||
},
|
||||
'slip:beforereorder .list': function(e, template) {
|
||||
if (e.originalEvent.target.className.indexOf('instant') == -1) {
|
||||
e.preventDefault();
|
||||
}
|
||||
},
|
||||
'slip:reorder .list': function(e, template) {
|
||||
spliceIndex = e.originalEvent.detail.spliceIndex
|
||||
originalIndex = e.originalEvent.detail.originalIndex
|
||||
|
||||
if (spliceIndex != originalIndex) {
|
||||
|
||||
template.data.collection.find({}, {
|
||||
sort: {
|
||||
order: 1
|
||||
}
|
||||
}).forEach(function(item, i) {
|
||||
//Pause the Observers while we update the order of each item.
|
||||
template.data.collection._collection.pauseObservers()
|
||||
if (spliceIndex != originalIndex) {
|
||||
|
||||
template.data.ionSortable.find({}, {
|
||||
sort: {
|
||||
order: 1
|
||||
}
|
||||
}).forEach(function(item, i) {
|
||||
template.data.ionSortable._collection.pauseObservers()
|
||||
if (item._id == Blaze.getData(e.target.getElementsByClassName('item-content')[0])._id) {
|
||||
temp = template.data.collection.update({
|
||||
_id: item._id
|
||||
}, {
|
||||
$set: {
|
||||
order: spliceIndex
|
||||
}
|
||||
})
|
||||
} else {
|
||||
if (spliceIndex > originalIndex) {
|
||||
newOrder = ((spliceIndex >= i) && (originalIndex < i)) ? (i - 1) : i
|
||||
} else if (spliceIndex == '0') {
|
||||
newOrder = (originalIndex > i) ? (i + 1) : i
|
||||
} else {
|
||||
newOrder = ((spliceIndex <= i) && (originalIndex > i)) ? (i + 1) : i
|
||||
temp = template.data.ionSortable.update({
|
||||
_id: item._id
|
||||
}, {
|
||||
$set: {
|
||||
order: spliceIndex
|
||||
}
|
||||
})
|
||||
} else {
|
||||
if (spliceIndex > originalIndex) {
|
||||
newOrder = ((spliceIndex >= i) && (originalIndex < i)) ? (i - 1) : i
|
||||
} else if (spliceIndex == '0') {
|
||||
newOrder = (originalIndex > i) ? (i + 1) : i
|
||||
} else {
|
||||
newOrder = ((spliceIndex <= i) && (originalIndex > i)) ? (i + 1) : i
|
||||
}
|
||||
|
||||
temp = template.data.collection.update({
|
||||
_id: item._id
|
||||
}, {
|
||||
$set: {
|
||||
order: newOrder
|
||||
}
|
||||
})
|
||||
temp = template.data.ionSortable.update({
|
||||
_id: item._id
|
||||
}, {
|
||||
$set: {
|
||||
order: newOrder
|
||||
}
|
||||
})
|
||||
}
|
||||
template.data.collection._collection.resumeObservers()
|
||||
})
|
||||
template.data.ionSortable._collection.resumeObservers()
|
||||
})
|
||||
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
|
@ -1,13 +1,3 @@
|
|||
Template.ionListButton.events({
|
||||
'click .item-delete' : function(e, template){
|
||||
e.preventDefault();
|
||||
itemContext = Template.parentData(1);
|
||||
template.data.collection._collection.remove({
|
||||
_id: itemContext._id
|
||||
}, function(error, result) { });
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
Template.ionListButton.helpers({
|
||||
classes: function(){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue