Refactor supplier settings

This commit is contained in:
2014-07-16 17:41:43 +02:00
parent a302123c6b
commit 2fec0b3bb6
31 changed files with 311 additions and 49 deletions
@@ -1,4 +1,15 @@
Qsupplier.App.ApplicationController = Ember.Controller.extend
init: ->
#@set 'supplier', @store.createRecord('supplier', name: 'kkkl')
@set 'supplier', @store.find('supplier', 'current')
#success = (supplier)=>
## A supplier record with id current and with the content of the returned supplier is created
## at the moment remove the dummy supplier, this should be resolved by Ember eventually
#if error_supplier = @store.all('supplier').findBy('id', 'current')
#error_supplier.eraseRecord()
#@set 'supplier', supplier
#error = (emberError)=>
#if error_supplier = @store.all('supplier').findBy('id', 'current')
#error_supplier.eraseRecord()
#@set 'supplier', null
#@store.find('supplier', 'current').then success, error
@set 'supplier', @store.find('supplier', supplier_id)
@@ -0,0 +1,9 @@
Qsupplier.App.SettingsController = Ember.ObjectController.extend
needs: ['application']
model: (-> @get('controllers.application.supplier')).property('controllers.application.supplier')
time_zones: (-> window.time_zones ).property()
countries: (-> window.countries ).property()
editIensProfile: (-> @get('model.country') is 'Netherlands' ).property('model.country')
actions:
saveSettings: ->
@get('model').save()
@@ -1,3 +1,15 @@
attr = DS.attr
Qsupplier.App.Supplier = DS.Model.extend
name: attr 'string'
email: attr 'string'
time_zone: attr 'string'
address: attr 'string'
house_number: attr 'number'
house_number_addition: attr 'string'
postal_code: attr 'string'
city: attr 'string'
country: attr 'string'
facebook_promotion_url: attr 'string'
iens_profile: attr 'string'
lat: attr 'number'
lng: attr 'number'
@@ -1,6 +1,9 @@
DS.Model.reopen
created_at: DS.attr('date')
updated_at: DS.attr('date')
eraseRecord: ->
@clearRelationships()
@transitionTo('deleted.saved')
DS.Model.reopenClass
findCached: (id)->
return null unless id
@@ -10,4 +10,5 @@ Qsupplier.App.Router.map ->
@resource 'section', path: ':section_id'
@resource 'lists', ->
@resource 'list', path: ':list_id'
@route 'settings'
#@resource 'lists', queryParams: ['state']
@@ -0,0 +1,7 @@
Qsupplier.App.SettingsRoute = Ember.Route.extend
model: ->
Em.RSVP.hash
supplier: @controllerFor('application').get('supplier')
setupController: (controller, model)->
#controller.set 'model', controller.get('controllers.application.supplier')
controller.set 'model', model.supplier
@@ -0,0 +1,40 @@
h2 These are Ember settings
.form-row
.form-label: label=t 'attributes.supplier.name'
.form-field: Ember.TextField valueBinding="controller.model.name"
.form-row
.form-label: label=t 'attributes.supplier.email'
.form-field: Qsupplier.App.EmailField valueBinding="controller.model.email"
/input.location_picker name="location" type="text" valueBinding="location"
/.form-row
.location_picker_map
= image_tag 'supplier/settings/location-balloon.png'
/.form-row
.form-label: label=t 'attributes.supplier.time_zone'
.form-field: Ember.Select content=time_zones optionValuePath="content.name" optionLabelPath="content.formatted" valueBinding="controller.model.time_zone"
.form-row
.form-label: label=t 'attributes.supplier.address'
.form-field.full
.row
.large-8.medium-8.columns: Ember.TextField valueBinding="controller.model.address"
.large-1.show-for-large-up.columns  
.large-2.medium-2.small-3.columns: Qsupplier.App.NumberField valueBinding="controller.model.house_number"
.large-1.medium-2.small-2.columns: Ember.TextField valueBinding="controller.model.house_number_addition"
.form-row
.form-label: label=t 'attributes.supplier.postal_code'
.form-field: Ember.TextField valueBinding="controller.model.postal_code"
.form-row
.form-label: label=t 'attributes.supplier.city'
.form-field: Ember.TextField valueBinding="controller.model.city"
.form-row
.form-label: label=t 'attributes.supplier.country'
.form-field: Ember.Select content=countries optionValuePath="content.name" optionLabelPath="content.name" valueBinding="controller.model.country"
if editIensProfile
.form-row
.form-label: label=t 'attributes.supplier.iens_profile'
.form-field
Qsupplier.App.NumberField valueBinding="controller.model.iens_profile"
= image_tag 'supplier/settings/iens-example.png'
span=t "settings.reviews.explanation"
.form-row.form-actions
button.button{action 'saveSettings'} Save settings
@@ -0,0 +1,14 @@
Qsupplier.App.ApplicationView = Ember.View.extend
didInsertElement: ->
selector_mappings =
'.top-menu-root': '/'
'.top-menu-lists': 'lists'
'.top-menu-sections': 'sections'
'.top-menu-lists': 'lists'
'.supplier-settings-link': 'settings'
for selector, route of selector_mappings
do (selector, route)=>
$(selector).click (e)=>
e.preventDefault()
@get('controller').transitionToRoute route
@@ -0,0 +1,3 @@
Qsupplier.App.EmailField = Ember.TextField.extend
type: 'email'
#attributeBindings: ['min', 'max', 'step']
@@ -0,0 +1,90 @@
Qsupplier.App.SettingsView = Ember.View.extend
templateName: 'settings'
didInsertElement: ->
return
iconBase = 'https://maps.google.com/mapfiles/kml/'
#location_input = @$('.location_picker')
#map_div = $('<div>').addClass("location_picker_map")
map_div = @$('.location_picker_map')
#location_input.before(map_div)
#this.parentNode.insertBefore(map_div, this)
#location_input.hide()
#lat = 52.07436798080633
#lng = 4.316811561584473
#if @get('controller.location') and @get('controller.location').split(',').length == 2
#values = @get('controller.location').split(',')
#lat = values[0]
#lng = values[1]
lat = @get('controller.model.lat')
lng = @get('controller.model.lng')
center = new google.maps.LatLng(lat,lng)
mapOptions =
zoom: 15
center: center
mapTypeId: google.maps.MapTypeId.ROADMAP,
zoomControl: true
zoomControlOptions:
style: google.maps.ZoomControlStyle.SMALL
mapTypeControl: false
panControl: false
scaleControl: false
streetViewControl: false
map = new google.maps.Map(map_div.get(0), mapOptions)
marker = new google.maps.Marker(
position: center
map: map
title: 'Location'
icon: '/assets/icons/maps_location.png'
)
google.maps.event.addListener(map, 'click', (point)=>
marker.setPosition(point.latLng)
#location_input.val point.latLng.lat() + ','+ point.latLng.lng()
@set 'controller.model.lat', point.latLng.lat()
@set 'controller.model.lng', point.latLng.lng()
)
search_field = $('<input type="text">')
search_field.addClass('location_picker_search')
autocomplete = new google.maps.places.Autocomplete(search_field.get(0))
autocomplete.bindTo('bounds', map)
search_field.keypress( (e) ->
if e.which == 13
e.preventDefault()
)
window.autocomplete = autocomplete
map_div.before(search_field)
infowindow = new google.maps.InfoWindow()
search_marker = new google.maps.Marker({map: map, icon: iconBase + 'shapes/placemark_circle.png'})
google.maps.event.addListener autocomplete, 'place_changed', ->
infowindow.close()
search_marker.setVisible(false)
place = autocomplete.getPlace()
return unless place.geometry
#if place.geometry.viewport
# map.fitBounds(place.geometry.viewport)
#else
map.setCenter(place.geometry.location)
map.setZoom(17)
image =
url: place.icon
size: new google.maps.Size(71, 71)
origin: new google.maps.Point(0, 0)
anchor: new google.maps.Point(17, 34)
scaledSize: new google.maps.Size(35, 35)
#search_marker.setIcon(image)
search_marker.setPosition(place.geometry.location)
search_marker.setVisible(true)
address = ''
if place.address_components
address = [
(place.address_components[0] && place.address_components[0].short_name || ''),
(place.address_components[1] && place.address_components[1].short_name || ''),
(place.address_components[2] && place.address_components[2].short_name || '')
].join(' ')
infowindow.setContent('<div><strong>' + place.name + '</strong><br>' + address + '</div>')
infowindow.open(map, search_marker)
@@ -23,6 +23,8 @@ $.extend($translations.nl, <%= I18n.t('supplier', locale: :nl).to_json %>);
String.prototype.capitalize = function() {
return this.charAt(0).toUpperCase() + this.slice(1);
}
window.time_zones = <%= ActiveSupport::TimeZone.all.map{|tz| {name: tz.name, formatted: "GMT#{tz.formatted_offset} #{tz.name}"}}.to_json.html_safe %>;
window.countries = <%= IsoCountryCodes.all.map{|cc| {name: cc.name}}.to_json.html_safe %>;
var path_mapping = {
user_root: '/user',
@@ -40,7 +40,26 @@ $ ->
setupTranslations()
# GOOGLE LOCATION PICKER
$('.toggle-side-menu,.side-menu').click ->
menu = $('aside.side-menu')
toggle = $('.toggle-side-menu')
if menu.is(':visible')
menu.animate left: -255, -> $(@).hide()
toggle.animate left: 0, -> $(@).removeClass('open')
else
menu.show().animate left: 0
toggle.animate left: 222 - 30, -> $(@).addClass('open')
$('[data-boolean]').each ->
$(@).addClass(if $(@).data('boolean') then 'boolean-true' else 'boolean-false')
# Hide alert boxes on click
$(document).on 'click', '.general-alerts .alert-box', -> $(@).slideUp()
$(document).on 'click', '.supplier-is-closed', -> $(@).slideUp()
# GOOGLE LOCATION PICKER
###
$("input.location_picker").each (i)->
#return if typeof(google) == 'undefined'
iconBase = 'https://maps.google.com/mapfiles/kml/'
@@ -124,21 +143,4 @@ $ ->
infowindow.setContent('<div><strong>' + place.name + '</strong><br>' + address + '</div>')
infowindow.open(map, search_marker)
# end google location map
$('.toggle-side-menu,.side-menu').click ->
menu = $('aside.side-menu')
toggle = $('.toggle-side-menu')
if menu.is(':visible')
menu.animate left: -255, -> $(@).hide()
toggle.animate left: 0, -> $(@).removeClass('open')
else
menu.show().animate left: 0
toggle.animate left: 222 - 30, -> $(@).addClass('open')
$('[data-boolean]').each ->
$(@).addClass(if $(@).data('boolean') then 'boolean-true' else 'boolean-false')
# Hide alert boxes on click
$(document).on 'click', '.general-alerts .alert-box', -> $(@).slideUp()
$(document).on 'click', '.supplier-is-closed', -> $(@).slideUp()
###
@@ -2,5 +2,5 @@ DS.Model.reopen
created_at: DS.attr('date')
updated_at: DS.attr('date')
eraseRecord: ->
@clearRelationships();
@transitionTo('deleted.saved');
@clearRelationships()
@transitionTo('deleted.saved')
@@ -11,3 +11,6 @@ aside.side-menu
list-style: none
a
color: white
.supplier-close-shop
+alert($bg: $alert-color, $radius: true)
padding: 3px
@@ -8,7 +8,7 @@
@import ./qdashboard
@import ./qdisplays
@import ./form_actions
@import ./qforms
@import ./components/*
@import ./menu_main
@import ./menu_side
@import ./qsections
@@ -15,8 +15,14 @@
@media #{$large-up}
+grid-column($columns: 3, $last-column:true)
&.full
@media #{$small-only}
+grid-column($columns:10, $center:true, $last-column:true)
@media #{$medium-only}
+grid-column($columns:6, $last-column:true)
@media #{$large-up}
+grid-column($columns: 9, $last-column:true)
&.form-actions
padding-top: 12px
body
label
&.number