Created
April 3, 2016 18:18
-
-
Save qrobin/bcab3f3588e44c3e541886bb94badf60 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
contentDistrictChooseMul: function(data_attr, collection, template) { | |
with(this.datafields(data_attr)) { | |
events[clickData] = function(e) { | |
let oldVal = e.target.innerText.split(','); | |
let arr = []; | |
for (var i = 0; i < oldVal.length; i++) { | |
let id = Districts.findOne({ name: oldVal[i] })._id; | |
arr.push(oldVal[i]) | |
} | |
let _id = this._id; | |
if (districtArr.length === 0) { | |
districtArr.push(Districts.find().map(function(it) { | |
return { | |
id: it._id, | |
text: it.name | |
} | |
})); | |
}; | |
districtArr = _.flatten(districtArr); | |
// e.target.textContent = ''; | |
let view = Blaze.renderWithData(Template.selectMul, Template.selectMul.helpers({ | |
options: function() { | |
return districtArr | |
}, | |
selected: function() { | |
return arr.indexOf(this.text) > -1 ? 'selected': ''; | |
} | |
}), | |
$(e.target).parent()[0] | |
); | |
select = $(e.target).parent().find('select'); | |
$(select).chosen({ | |
width: '50%' | |
}).chosen('open'); | |
$(select).blur(function(e) { | |
let self = this; | |
// newVal = e.target.find("option:selected").map(function(index, elem) { | |
// return elem.innerText; | |
// }); | |
console.log(e); | |
console.log(newVal); | |
// newValDB = $(this).chosen('data')[0].id; | |
$('.select').chosen('destroy'); | |
Blaze.remove(view); | |
if (oldVal !== newVal) { | |
collection.findAndModify({ | |
query: { _id: _id }, | |
update: { $set: { district_id: newValDB } }, | |
new: false | |
}); | |
districtArr = [] | |
$.notify({ | |
title: "Изменения в базе данных: ", | |
message: `район: ${newVal}` | |
}, _notifyMethods.success) | |
} else { | |
$.notify({ | |
title: "База данных: ", | |
message: "без изменений" | |
}, | |
_notifyMethods.default) | |
e.target.textContent = oldVal; | |
districtArr = [] | |
} | |
}); | |
$('.chzn-choices').on('blur', function(e) { | |
console.log('dasdsad'); | |
$(e.target).parent().find('select').chosen('destroy'); | |
Blaze.remove(view); | |
e.target.textContent = oldVal; | |
districtArr = [] | |
}); | |
} | |
template.events(events); | |
} | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment