Last active
February 4, 2016 20:48
-
-
Save qrobin/5b70f8579bb774dbf67b 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
Transfer_Orders = new Mongo.Collection('transfer_orders'); | |
Transfer_Orders.attachSchema(new SimpleSchema({ | |
transfer: { | |
type: String, | |
label: "Выберите трансфер", | |
optional: true, | |
autoform: { | |
type: "select", | |
firstOption: "", | |
options: function() { | |
return Transfers.find().map(function(it) { | |
return { | |
label: Districts.findOne({ | |
_id: it.direction.from_district | |
}).name + ' - ' + Districts.findOne({ | |
_id: it.direction.to_district | |
}).name, | |
value: it._id | |
}; | |
}); | |
} | |
} | |
}, | |
date_time: { | |
type: String, | |
label: "Дата и время", | |
optional: true, | |
autoform: { | |
afFieldInput: { | |
class: "date" | |
} | |
}, | |
}, | |
return_date_time: { | |
type: String, | |
label: "Дата и время возвращения", | |
optional: true, | |
autoform: { | |
afFieldInput: { | |
class: "date" | |
} | |
}, | |
}, | |
pax: { | |
type: Number, | |
label: "Взрослых", | |
optional: true | |
}, | |
place_from: { | |
type: String, | |
label: "Откуда ехать", | |
optional: true, | |
autoform: { | |
type: "select", | |
firstOption: "", | |
options: function() { | |
if (Meteor.isClient) { | |
var curr_transfer2 = ''; | |
var district_from = ''; | |
curr_transfer2 = AutoForm.getFieldValue('transfer', 'TransferSchema'); | |
if (curr_transfer2) { | |
district_from = Transfers.findOne({ | |
_id: curr_transfer2 | |
}).direction.from_district; | |
return Places.find({ | |
district: district_from | |
}).map(function(it) { | |
return { | |
label: it.name, | |
value: it._id | |
}; | |
}); | |
}; | |
}; | |
} | |
} | |
}, | |
price: { | |
type: Number, | |
label: "Цена", | |
optional: true | |
}, | |
room: { | |
type: String, | |
label: "Номер комнаты", | |
optional: true, | |
}, | |
order_status: { | |
type: String, | |
label: "Присвоить статус", | |
optional: true, | |
autoform: { | |
type: "select", | |
firstOption: "", | |
options: function() { | |
return [ | |
{ | |
label: "Лид", | |
value: 'order_lead' | |
}, { | |
label: "Перезвонить клиенту", | |
value: 'order_recall' | |
}, { | |
label: "Ожидание данных", | |
value: 'order_waiting' | |
}, { | |
label: "Отправить организатору", | |
value: 'order_sent' | |
} | |
] | |
} | |
} | |
}, | |
direction: { | |
type: String, | |
label: "Направление", | |
optional: true, | |
autoform: { | |
type: "select", | |
firstOption: "", | |
options: function() { | |
return [ | |
{ | |
label: "В один конец", | |
value: 'prices_one_direction' | |
}, { | |
label: "В оба конца", | |
value: 'prices_two_directions' | |
} | |
] | |
} | |
} | |
}, | |
prices_avaible: { | |
type: String, | |
label: "Способы", | |
optional: true, | |
autoform: { | |
type: "select", | |
firstOption: "", | |
options: function() { | |
curr_transfer3 = AutoForm.getFieldValue('transfer', 'TransferSchema'); | |
curr_prices = AutoForm.getFieldValue('direction', 'TransferSchema'); | |
pricesArr = []; | |
if (curr_prices === 'prices_one_direction') { | |
pricesArr.splice(0, pricesArr.length); | |
pricesArr.push(Object.keys(Transfers.findOne({ | |
_id: curr_transfer3 | |
}).prices_one_direction)); | |
} else if (curr_prices === 'prices_two_directions') { | |
pricesArr.splice(0, pricesArr.length); | |
pricesArr.push(Object.keys(Transfers.findOne({ | |
_id: curr_transfer3 | |
}).prices_two_directions)); | |
} else { | |
pricesArr.splice(0, pricesArr.length); | |
}; | |
return _.flatten(pricesArr).map(function(a) { | |
return { | |
value: a, | |
label: a | |
} | |
}) | |
} | |
} | |
}, | |
pax_one_way: { | |
type: Number, | |
label: "Людей (туда)", | |
optional: true | |
}, | |
pax_two_ways: { | |
type: Number, | |
label: "Людей (назад)", | |
optional: true | |
}, | |
additional_info: { | |
type: String, | |
label: "Дополнительно", | |
optional: true, | |
autoform: { | |
afFieldInput: { | |
type: "textarea" | |
} | |
} | |
}, | |
additional_question: { | |
type: String, | |
label: "Доп. вопросы организатору", | |
optional: true, | |
autoform: { | |
afFieldInput: { | |
type: "textarea" | |
} | |
} | |
}, | |
date_created: { | |
type: Date, | |
autoform: { | |
type: 'hidden', | |
}, | |
autoValue: function() { | |
if (this.isInsert) { | |
return new Date().valueOf(); | |
} else if (this.isUpsert) { | |
return { | |
$setOnInsert: new Date().valueOf() | |
}; | |
} else { | |
this.unset(); | |
} | |
} | |
}, | |
who_created: { | |
type: String, | |
autoform: { | |
type: 'hidden' | |
}, | |
autoValue: function() { | |
return this.userId; | |
} | |
}, | |
type: { | |
type: String, | |
autoform: { | |
type: 'hidden' | |
}, | |
autoValue: function() { | |
return "Трансфер" | |
} | |
} | |
})); |
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
<template name="orderTransfer"> | |
<div class="placer"></div> | |
<div class="containerr"> | |
{{# autoForm id="TransferSchema" type="insert" collection="Transfer_Orders" }} | |
<div class="roww"> | |
<div class="coll spann_6"> | |
{{> afQuickField name="transfer"}} | |
{{> afQuickField name="place_from"}} | |
{{> afQuickField name="room"}} | |
{{> afQuickField name="date_time"}} | |
{{> afQuickField name="additional_info"}} | |
{{> afQuickField name="order_status"}} | |
</div> | |
<div class="coll spann_2"> | |
<h1 class="invisible">11</h1> | |
</div> | |
<div class="coll spann_6"> | |
{{> afQuickField name="direction"}} | |
{{> afQuickField name="pax_one_way"}} | |
{{> afQuickField name="pax_two_ways"}} | |
{{> afQuickField name="return_date_time"}} | |
{{> afQuickField name="prices_avaible"}} | |
{{> afQuickField name="price"}} | |
{{> afQuickField name="additional_question"}} | |
</div> | |
<div class="coll spann_2"> | |
<h1 class="invisible">11</h1> | |
</div> | |
</div> | |
<div class="roww"> | |
<div class="coll spann_6"> | |
</div> | |
</div> | |
<div class="roww"> | |
<div class="form-group"> | |
<button type="submit" class="btn btn-success">Отправить заказ</button> | |
<button type="reset" class="btn btn-default">Сбросить</button> | |
</div> | |
</div> | |
{{/autoForm}} | |
</div> | |
<script> | |
$("input[name='room']").closest('div.form-group').hide(); | |
$("input[name='return_date_time']").closest('div.form-group').hide(); | |
$("input[name='pax_two_ways']").closest('div.form-group').hide(); | |
</script> | |
</template> |
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.subscribe("Transfer_Orders"); | |
var week_arr = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; | |
Template.orderTransfer.rendered = function() { | |
$('.date').datetimepicker({ | |
useStrict: false, | |
sideBySide: true, | |
calendarWeeks: false, | |
viewMode: 'days', | |
toolbarPlacement: 'default', | |
showTodayButton: true, | |
showClear: true, | |
showClose: true, | |
}); | |
}; | |
Template.orderTransfer.events({ | |
'change select[data-schema-key="transfer"]': function(event) { | |
if ($('select[data-schema-key="transfer"]').val()) { | |
$('.date').data("DateTimePicker").destroy(); | |
// Автоматический подгон выходных в форму | |
Session.set('transfer', $('select[data-schema-key="transfer"]').val()); | |
curr_transfer = Session.get('transfer'); | |
var _weekDays = Transfers.findOne({ | |
_id: curr_transfer | |
}).off_weekdays; | |
result = []; | |
for (var i in _weekDays) { | |
result.push(week_arr.indexOf(_weekDays[i])) | |
}; | |
$('.date').datetimepicker({ | |
daysOfWeekDisabled: result, | |
useStrict: false, | |
sideBySide: true, | |
calendarWeeks: false, | |
viewMode: 'days', | |
toolbarPlacement: 'default', | |
showTodayButton: true, | |
showClear: true, | |
showClose: true, | |
}); | |
}; | |
}, | |
'change select[data-schema-key="place_from"]': function(event) { | |
Session.set('place_from', $("select[data-schema-key='place_from']").val()); | |
var place_from = Session.get('place_from'); | |
var place_type = Places.findOne({ | |
_id: place_from | |
}).place_type; | |
if (place_type === "hotel") { | |
$("input[name='room']").closest('div.form-group').show(); | |
} else { | |
$("input[name='room']").closest('div.form-group').hide(); | |
}; | |
}, | |
'change select[data-schema-key="direction"]': function(event) { | |
Session.set('direction', $("select[data-schema-key='direction']").val()); | |
if (Session.get('direction') === "prices_two_directions") { | |
$("input[name='return_date_time']").closest('div.form-group').show(); | |
$("input[name='pax_two_ways']").closest('div.form-group').show(); | |
$('.date').datetimepicker({ | |
daysOfWeekDisabled: result, | |
useStrict: false, | |
sideBySide: true, | |
calendarWeeks: false, | |
viewMode: 'days', | |
toolbarPlacement: 'default', | |
showTodayButton: true, | |
showClear: true, | |
showClose: true, | |
}); | |
} else if (Session.get('direction') === "prices_one_direction") { | |
$("input[name='return_date_time']").closest('div.form-group').hide(); | |
$("input[name='pax_two_ways']").closest('div.form-group').hide(); | |
}; | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment