Last active
March 13, 2016 11:18
-
-
Save qrobin/12b34bb9bfec4467ab32 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
myMethods = { | |
datafields: { | |
data: `span[data-field= ${this.dataAttrMeth}]`, | |
clickData: `click span[data-field= ${this.dataAttrMeth}]`, | |
keyData: `keypress span[data-field= ${this.dataAttrMeth}]`, | |
blurData: `blur span[data-field= ${this.dataAttrMeth}]`, | |
events: {}, | |
oldVal: '', | |
newVal: '', | |
dataAttrMeth: function(data_attr) { | |
return data_attr | |
} | |
}, | |
contenteditable: function(data_attr, Collection, template, editTarget) { | |
with(this.datafields) { | |
events[clickData] = function(e) { | |
console.log(data); | |
$(data).attr('contenteditable', true); | |
oldVal = e.target.textContent; | |
}; | |
events[blurData] = function(e) { | |
$(data).attr('contenteditable', false); | |
newVal = e.target.textContent; | |
if (oldVal !== newVal) { | |
let result = {}; | |
let key = editTarget.db; | |
result[key] = newVal; | |
console.log(result); | |
Collection.findAndModify({ | |
query: { _id: this._id }, | |
update: { $set: result }, | |
new: false | |
}); | |
$(e.target).text(''); | |
$.notify({ | |
title: `Изменения в базе данных: `, | |
message: `<br> ${editTarget.ru}: ${newVal}` | |
}, _notifyMethods.success) | |
} else { | |
$.notify({ | |
title: "База данных: ", | |
message: "<br>без изменений" | |
}, | |
_notifyMethods.default); | |
} | |
}; | |
events[keyData] = function(ev) { | |
if (ev.keyCode == 13 || ev.which == 13) { | |
ev.preventDefault ? ev.preventDefault() : ev.returnValue = false | |
events[blurData]() | |
} | |
}; | |
template.events(events); | |
} | |
} | |
} |
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
myMethods = { | |
contenteditable: function(data_attr, Collection, template, editTarget) { | |
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.target.textContent; | |
if (oldVal !== newVal) { | |
let result = {}; | |
let key = editTarget.db; | |
result[key] = newVal; | |
console.log(result); | |
Collection.findAndModify({ | |
query: { _id: this._id }, | |
update: { $set: result }, | |
new: false | |
}); | |
$(e.target).text(''); | |
$.notify({ | |
title: `Изменения в базе данных: `, | |
message: `<br> ${editTarget.ru}: ${newVal}` | |
}, _notifyMethods.success) | |
} else { | |
$.notify({ | |
title: "База данных: ", | |
message: "<br>без изменений" | |
}, | |
_notifyMethods.default); | |
} | |
}; | |
events[keyData] = function(ev) { | |
if (ev.keyCode == 13 || ev.which == 13) { | |
ev.preventDefault ? ev.preventDefault() : ev.returnValue = false | |
events[blurData]() | |
} | |
}; | |
template.events(events); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment