From 627e0e891db6ebcdc13f8c87da9a00e842ec1bce Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Wed, 2 Jul 2014 15:44:51 +0200 Subject: [PATCH] Better supplier ember section workflow --- .../modal_add_section_controller.js.coffee | 39 +++++++++++++++++++ .../controllers/section_controller.js.coffee | 8 ++++ .../sections_index_controller.js.coffee | 1 + .../app/templates/modal_add_section.emblem | 24 ++++++++++++ .../supplier/app/templates/section.emblem | 4 +- .../app/templates/sections/index.emblem | 2 +- .../javascripts/translations.js.coffee.erb | 14 ++++++- .../supplier/foundation1/_qmodal.css.sass | 2 + .../foundation1/_section_tab_headers.css.sass | 9 ++++- .../suppliers/sections_controller.rb | 2 +- .../supplier_section_serializer.rb | 4 ++ app/views/suppliers/tables/qr_codes.html.slim | 2 +- config/locales/supplier.en.yml | 5 +++ config/locales/supplier.nl.yml | 5 +++ 14 files changed, 115 insertions(+), 6 deletions(-) create mode 100644 app/assets/javascripts/supplier/app/controllers/modal_add_section_controller.js.coffee create mode 100644 app/assets/javascripts/supplier/app/templates/modal_add_section.emblem create mode 100644 app/serializers/supplier_section_serializer.rb diff --git a/app/assets/javascripts/supplier/app/controllers/modal_add_section_controller.js.coffee b/app/assets/javascripts/supplier/app/controllers/modal_add_section_controller.js.coffee new file mode 100644 index 00000000..bcd5296e --- /dev/null +++ b/app/assets/javascripts/supplier/app/controllers/modal_add_section_controller.js.coffee @@ -0,0 +1,39 @@ +Qsupplier.App.ModalAddSectionController = Ember.ObjectController.extend + alert_message: null + section_name: '' + section_width: 15 + section_height: 8 + actions: + close: -> + @set 'alert_message', null + @get('model.cancel').call(@) if @get('model.cancel') + @send 'closeModal' + addSection: -> + @set 'alert_message', null + title = @get('section_title') + width = @get('section_width') + height = @get('section_height') + unless title + @set 'alert_message', error_message + attribute: t('attributes.section.title') + message: 'blank' + return + unless parseInt(width) > 0 + @set 'alert_message', error_message + attribute: t('attributes.section.width') + message: 'greater_than' + count: 0 + return + unless parseInt(height) > 0 + @set 'alert_message', error_message + attribute: t('attributes.section.height') + message: 'greater_than' + count: 0 + return + section = @store.createRecord 'section', + title: title + width: width + height: height + section.save().then (s)=> + @send 'closeModal' + @transitionToRoute 'section', s.id diff --git a/app/assets/javascripts/supplier/app/controllers/section_controller.js.coffee b/app/assets/javascripts/supplier/app/controllers/section_controller.js.coffee index 91d95a57..63cd844c 100644 --- a/app/assets/javascripts/supplier/app/controllers/section_controller.js.coffee +++ b/app/assets/javascripts/supplier/app/controllers/section_controller.js.coffee @@ -8,11 +8,19 @@ Qsupplier.App.SectionController = Ember.ObjectController.extend finishEditable: -> @set('editmode', false) @get('model').save() + addSection: -> + @send 'openModal', 'modal_add_section', @get('model') addTables: -> #$('#add-tables-modal').modal() @send 'openModal', 'modal_section_add_tables', @get('model') arrangeTables: -> @send 'openModal', 'modal_section_arrange_tables', @get('model') + destroySection: -> + @send 'openModal', 'modal_confirm', + title: t('helpers.links.are_you_sure') + ok: => + @get('model').destroyRecord() + @transitionToRoute 'sections' textures: ['wood1', 'wood2'] sections: (-> @get('controllers.sections.model')).property('controllers.sections.model') diff --git a/app/assets/javascripts/supplier/app/controllers/sections_index_controller.js.coffee b/app/assets/javascripts/supplier/app/controllers/sections_index_controller.js.coffee index 2570cabb..1b5ddbd2 100644 --- a/app/assets/javascripts/supplier/app/controllers/sections_index_controller.js.coffee +++ b/app/assets/javascripts/supplier/app/controllers/sections_index_controller.js.coffee @@ -12,3 +12,4 @@ Qsupplier.App.SectionsIndexController = Ember.ArrayController.extend showDashboardOrders: (section)-> @transitionToRoute('index').then => @get('controllers.index').set 'active_section', section + addSection: -> @send 'openModal', 'modal_add_section', @get('model') diff --git a/app/assets/javascripts/supplier/app/templates/modal_add_section.emblem b/app/assets/javascripts/supplier/app/templates/modal_add_section.emblem new file mode 100644 index 00000000..ff203429 --- /dev/null +++ b/app/assets/javascripts/supplier/app/templates/modal_add_section.emblem @@ -0,0 +1,24 @@ +modal-dialog action="close" + h3.flush--top=t 'section.add_section.modal.title' + p==body + .modal-body + .modal-alert== alert_message + .form-row + .form-label + label=t 'attributes.section.title' + .form-field + Ember.TextField valueBinding="section_title" + .form-row + .form-label + label=t 'attributes.section.width' + .form-field + Qsupplier.App.NumberField valueBinding="section_width" + .form-row + .form-label + label=t 'attributes.section.height' + .form-field + Qsupplier.App.NumberField valueBinding="section_height" + .modal-footer + hr + button.confirm-cancel{action "close"}=t 'section.add_section.modal.close_button' + button.confirm-ok.right{action "addSection"}=t 'section.add_section.modal.add_button' diff --git a/app/assets/javascripts/supplier/app/templates/section.emblem b/app/assets/javascripts/supplier/app/templates/section.emblem index e1d51559..5d891eb8 100644 --- a/app/assets/javascripts/supplier/app/templates/section.emblem +++ b/app/assets/javascripts/supplier/app/templates/section.emblem @@ -2,6 +2,7 @@ link-to 'sections' class="goto-sections-index-tab-header": span each section in sections view Qsupplier.App.SectionTabHeaderView context=section + a.add-section{action "addSection"}: span .section-manage-tables.pull-right if editmode /.btn-group @@ -31,7 +32,8 @@ span.table-qr-codes =t 'tables.qr_codes.link' li - a.section-destroy href="{{route 'suppliers_section_path' id}}" data-method="delete" data-confirm="{{t 'helpers.links.are_you_sure' bare=true}}" + /a.section-destroy href="{{route 'suppliers_section_path' id}}" data-method="delete" data-confirm="{{t 'helpers.links.are_you_sure' bare=true}}" + a.section-destroy{action destroySection} span.section-remove-icon =t 'helpers.links.destroy' Ember.TextField valueBinding="title" class="section-edit-title-field" diff --git a/app/assets/javascripts/supplier/app/templates/sections/index.emblem b/app/assets/javascripts/supplier/app/templates/sections/index.emblem index 3b5de10d..aa30c7e6 100644 --- a/app/assets/javascripts/supplier/app/templates/sections/index.emblem +++ b/app/assets/javascripts/supplier/app/templates/sections/index.emblem @@ -38,4 +38,4 @@ else .row .panel=t 'section.none_found' .form-actions - a.form-action-new{path new_suppliers_section}=t 'helpers.links.new' + a.form-action-new{action "addSection"}=t 'helpers.links.new' diff --git a/app/assets/javascripts/translations.js.coffee.erb b/app/assets/javascripts/translations.js.coffee.erb index 34236f2e..c4f453ec 100644 --- a/app/assets/javascripts/translations.js.coffee.erb +++ b/app/assets/javascripts/translations.js.coffee.erb @@ -4,12 +4,13 @@ attributes: <%= I18n.t('activemodel.attributes', locale: :en).to_json %> helpers: <%= I18n.t('helpers', locale: :en).to_json %> pagination: <%= I18n.t('views.pagination', locale: :en).to_json %> + errors: <%= I18n.t('errors', locale: :en).to_json %> nl: models: <%= I18n.t('activemodel.models', locale: :nl).to_json %> attributes: <%= I18n.t('activemodel.attributes', locale: :nl).to_json %> helpers: <%= I18n.t('helpers', locale: :nl).to_json %> pagination: <%= I18n.t('views.pagination', locale: :nl).to_json %> - + errors: <%= I18n.t('errors', locale: :nl).to_json %> @t = (path, vars={}) -> #result = undefined #m = undefined @@ -95,6 +96,17 @@ datepicker_object.pickadate(window.pickadate_options) datepicker_object.change() +# use like +# error_message +# attribute: t('attributes.section.title') +# message: 'blank' +@error_message = (options = {})-> + locale = options.locale || Qstorage.getItem('locale') || 'en' + #message = $translations[locale].errors.messages[options.message] + message = t "errors.messages.#{options.message}", options + t 'errors.format', + attribute: options.attribute + message: message @setupTranslations = (options = {})-> locale = options.locale || Qstorage.getItem('locale') || 'en' diff --git a/app/assets/stylesheets/supplier/foundation1/_qmodal.css.sass b/app/assets/stylesheets/supplier/foundation1/_qmodal.css.sass index 98eeefcd..0b24b11f 100644 --- a/app/assets/stylesheets/supplier/foundation1/_qmodal.css.sass +++ b/app/assets/stylesheets/supplier/foundation1/_qmodal.css.sass @@ -3,6 +3,8 @@ width: 500px background-color: #fff padding: 1em +.modal-alert + color: $alert-color .overlay height: 100% diff --git a/app/assets/stylesheets/supplier/foundation1/_section_tab_headers.css.sass b/app/assets/stylesheets/supplier/foundation1/_section_tab_headers.css.sass index 76ebf99b..e9131fc5 100644 --- a/app/assets/stylesheets/supplier/foundation1/_section_tab_headers.css.sass +++ b/app/assets/stylesheets/supplier/foundation1/_section_tab_headers.css.sass @@ -21,11 +21,18 @@ background-image: image-url('supplier/drop-target.svg') &.table-hover background-image: image-url('supplier/drop-target-active.svg') - &:after content: '' display: block clear: left + .add-section + display: inline-block + margin-top: 8px + span + @extend .fa + @extend .fa-lg + @extend .fa-plus + .goto-sections-index-tab-header float: left span diff --git a/app/controllers/suppliers/sections_controller.rb b/app/controllers/suppliers/sections_controller.rb index e6f37fd2..7605f504 100644 --- a/app/controllers/suppliers/sections_controller.rb +++ b/app/controllers/suppliers/sections_controller.rb @@ -61,7 +61,7 @@ module Suppliers respond_to do |format| if @section.save format.html { redirect_to [:suppliers, @section], notice: t('action.create.successfull', model: Section.model_name.human) } - format.json { render json: @section, status: :created, location: @section } + format.json { render json: @section, serializer: SupplierSectionSerializer, status: :created } else format.html { render action: "new" } format.json { render json: @section.errors, status: :unprocessable_entity } diff --git a/app/serializers/supplier_section_serializer.rb b/app/serializers/supplier_section_serializer.rb new file mode 100644 index 00000000..d0826429 --- /dev/null +++ b/app/serializers/supplier_section_serializer.rb @@ -0,0 +1,4 @@ +class SupplierSectionSerializer < Qwaiter::Serializer + root 'section' + attributes :title, :path, :width, :height +end diff --git a/app/views/suppliers/tables/qr_codes.html.slim b/app/views/suppliers/tables/qr_codes.html.slim index dca17de4..c6671be9 100644 --- a/app/views/suppliers/tables/qr_codes.html.slim +++ b/app/views/suppliers/tables/qr_codes.html.slim @@ -1,3 +1,3 @@ ul#qr-list - for table in @tables - li= image_tag(url_for(table_qr_image_path(table_id: table.id, format: :png))) + li= image_tag(url_for(table_qr_image_path(table_id: table.id, format: :svg))) diff --git a/config/locales/supplier.en.yml b/config/locales/supplier.en.yml index d14a1ad8..e4111080 100644 --- a/config/locales/supplier.en.yml +++ b/config/locales/supplier.en.yml @@ -58,6 +58,11 @@ en: number_end: Till number close_button: Close add_button: Add + add_section: + modal: + title: 'New ${models.section}' + close_button: Close + add_button: Create arrange_tables: button_label: Arrange tables by_row_no_row_count: 'Please fill in a positive number representing the number of ${models.plural.table|downcase} per row' diff --git a/config/locales/supplier.nl.yml b/config/locales/supplier.nl.yml index 04960817..1b1fff3a 100644 --- a/config/locales/supplier.nl.yml +++ b/config/locales/supplier.nl.yml @@ -58,6 +58,11 @@ nl: number_end: Tot nummer close_button: Sluiten add_button: Voeg toe + add_section: + modal: + title: '${models.section} toevoegen' + close_button: Sluiten + add_button: Aanmaken arrange_tables: button_label: Positioneer tafels by_row_no_row_count: 'Geef een positief getal voor het aantal ${models.plural.table|downcase} per rij'