Skip to content

Instantly share code, notes, and snippets.

@victorpavlenko victorpavlenko/view.js
Last active Aug 29, 2015

Embed
What would you like to do?
view
var createView = function(settings, type){
var template,
context;
if(type == 'documents'){
/** Рисуем шаблон документов **/
var documentFormat = [];
for ( var k in settings.documents.format) {
documentFormat.push('<option value="' + settings.documents.format[k] + '">' + k + '</option>')
};
documentFormat = documentFormat.join(' ');
template = Handlebars.compile( $("#documents").html() );
context = {
format : documentFormat
};
return template(context);
} else if (type == 'images'){
/** Рисуем шаблон изображений **/
var imagepaperType = [];
var imageFormat = [];
$.each(settings.images.format, function(i, v) {
imageFormat.push( '<option value="' + v + '">Размеры ' + i + ' см</option>')
});
for(var key in settings.images.paperType ) {
imagepaperType.push( '<option value="' + key + '">'+ settings.images.paperType[key] + '</option>')
}
imageFormat = imageFormat.join(' ');
imagepaperType = imagepaperType.join(' ');
template = Handlebars.compile($("#images").html());
context = {
format : imageFormat,
type : imagepaperType
};
return template(context);
} else {
/** Рисуем шаблон визиток **/
var cardsCount = [];
var cardpaperType = [];
for(var keys in settings.cards.paperType){
cardpaperType.push( '<option value="' + keys + '">' + settings.cards.paperType[keys] + '</option>')
};
$.each(settings.cards.count, function(val, item){
cardsCount.push( '<option value="' + item + '">' + item + '</option>')
});
cardpaperType = cardpaperType.join('');
cardsCount = cardsCount.join('');
template = Handlebars.compile($("#cards").html());
context = {
count : cardsCount,
type : cardpaperType
};
return template(context);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.