Created
March 11, 2016 17:11
-
-
Save qrobin/0c9a987521664feead12 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Meteor.call('contenteditable', 'name', Places, Template.tableInsider, function(e, r) { | |
console.log('e', e); | |
console.log('r', r); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Meteor.methods({ | |
contenteditable: function(data_attr, Collection, template) { | |
let data = `span[data-field= ${data_attr}]`; | |
let clickData = 'click span[data-field=' + data_attr + ']'; | |
let keyData = 'keypress span[data-field=' + data_attr + ']'; | |
let blurData = 'blur span[data-field=' + data_attr + ']'; | |
let events = {}; | |
let oldVal = ''; | |
let newVal = ''; | |
events[clickData] = function(e) { | |
$(data).attr('contenteditable', true); | |
oldVal = e.target.textContent; | |
}; | |
events[blurData] = function(e) { | |
$(data).attr('contenteditable', false); | |
newVal = e.currentTarget.textContent; | |
if (oldVal !== newVal) { | |
Collection.findAndModify({ | |
query: { _id: this._id }, | |
update: { $set: { name: e.currentTarget.textContent } }, | |
new: false | |
}); | |
console.log('Document modifyed'); | |
$(e.target).text('') | |
console.log('HTML cleared'); | |
}; | |
}; | |
events[keyData] = function(ev) { | |
if (ev.keyCode == 13 || ev.which == 13) { | |
ev.preventDefault ? ev.preventDefault() : ev.returnValue = false | |
console.log('Enter prevented'); | |
events[blurData]() | |
} | |
}; | |
template.events(events); | |
}, | |
contentDistrictChoose: function(data_attr, Collection, template) { | |
let data = `span[data-field= ${data_attr}]`; | |
let clickData = 'click span[data-field=' + data_attr + ']'; | |
let blurData = 'blur span[data-field=' + data_attr + ']'; | |
let events = {}; | |
let oldVal = ''; | |
let newVal = ''; | |
let districtArr = []; | |
console.log(districtArr); | |
events[clickData] = function(e) { | |
oldVal = e.target.innerText; | |
districtArr.push(Districts.find().map(function(it) { | |
return { | |
id: it._id, | |
text: it.name | |
} | |
})); | |
console.log(districtArr); | |
$(e.currentTarget).select2({ | |
useEmpty: true, | |
data: _.flatten(districtArr), | |
placeholder: 'Изменить район', | |
width: '190px' | |
}); | |
console.log(oldVal); | |
}; | |
events[blurData] = function(e) { | |
$(e.currentTarget).select2('destroy'); | |
newVal = e.currentTarget.textContent; | |
// if (oldVal !== newVal) { | |
// Collection.findAndModify({ | |
// query: { _id: this._id }, | |
// update: { $set: { name: e.currentTarget.textContent } }, | |
// new: false | |
// }); | |
// console.log('edited'); | |
// }; | |
}; | |
template.events(events); | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment