diff --git a/components/ionItem/ionItem.js b/components/ionItem/ionItem.js index 90d957b..811345d 100644 --- a/components/ionItem/ionItem.js +++ b/components/ionItem/ionItem.js @@ -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'); } diff --git a/components/ionList/ionList.js b/components/ionList/ionList.js index eb4ad16..478d227 100644 --- a/components/ionList/ionList.js +++ b/components/ionList/ionList.js @@ -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() + }) - } - }, +} +} }); \ No newline at end of file diff --git a/components/ionListButton/ionListButton.js b/components/ionListButton/ionListButton.js index b760893..bf2b283 100644 --- a/components/ionListButton/ionListButton.js +++ b/components/ionListButton/ionListButton.js @@ -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(){