improved shared database import ui
This commit is contained in:
parent
950480941a
commit
0014435663
8 changed files with 97 additions and 61 deletions
|
@ -208,9 +208,15 @@ class ArticlesController < ApplicationController
|
|||
end
|
||||
|
||||
# fills a form whith values of the selected shared_article
|
||||
# when the direct parameter is set and the article is valid, it is imported directly
|
||||
def import
|
||||
@article = SharedArticle.find(params[:shared_article_id]).build_new_article(@supplier)
|
||||
render :action => 'new', :layout => false
|
||||
@article.article_category_id = params[:article_category_id] unless params[:article_category_id].blank?
|
||||
if params[:direct] and not params[:article_category_id].blank? and @article.valid? and @article.save
|
||||
render :action => 'create', :layout => false
|
||||
else
|
||||
render :action => 'new', :layout => false
|
||||
end
|
||||
end
|
||||
|
||||
# sync all articles with the external database
|
||||
|
|
4
app/views/articles/_import_article_added.js.erb
Normal file
4
app/views/articles/_import_article_added.js.erb
Normal file
|
@ -0,0 +1,4 @@
|
|||
// update shared article button on create, so that the article will be shown as imported
|
||||
// reloading the list doesn't work because it breaks paging :(
|
||||
$('#shared_article_<%= article.shared_article.id %> .actions')
|
||||
.html('<%= j content_tag(:i, I18n.t('articles.import_search_results.already_imported'), class: 'icon-ok')%>');
|
|
@ -11,22 +11,23 @@
|
|||
%th= heading_helper Article, :note
|
||||
%th{:style => "width:4em"}= heading_helper Article, :price
|
||||
%th= heading_helper Article, :unit
|
||||
%th= heading_helper Article, :unit_quantity, short: true
|
||||
%th
|
||||
%tbody
|
||||
- for article in @articles
|
||||
%tr
|
||||
%tr{id: "shared_article_#{article.id}"}
|
||||
%td= highlight article.name, params[:q][:name_cont_all]
|
||||
%td= article.origin
|
||||
%td= article.manufacturer
|
||||
%td= article.note
|
||||
%td{title: article.note}= truncate(article.note, length: 11)
|
||||
%td= number_to_currency(article.price)
|
||||
%td= article.unit
|
||||
%td= article.unit_quantity
|
||||
%td
|
||||
= article.unit
|
||||
- if article.unit_quantity > 1
|
||||
%span{style: 'color: grey'} × #{article.unit_quantity} #{pkg_helper_icon}
|
||||
%td.actions
|
||||
- logger.debug "[debug] #{article.attributes.inspect}"
|
||||
- if @supplier.articles.undeleted.where(order_number: article.number).exists?
|
||||
%i.icon-ok= t '.already_imported'
|
||||
- else
|
||||
= link_to t('.action_import'), import_supplier_articles_path(@supplier, :shared_article_id => article.id),
|
||||
:remote => true, class: 'btn btn-small btn-success'
|
||||
= link_to t('.action_import'), import_supplier_articles_path(@supplier, shared_article_id: article.id, direct: true),
|
||||
remote: true, class: 'btn btn-small btn-success'
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
$('#modalContainer').modal('hide');
|
||||
$('#listbody').prepend('#{escape_javascript(render(@article))}');
|
||||
= render 'import_article_added', article: @article if @article.shared_article
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
- title t('.title', supplier: @supplier.name, count: @supplier.articles.undeleted.count)
|
||||
|
||||
.well.well-small
|
||||
.btn-toolbar
|
||||
= form_tag supplier_articles_path(@supplier), method: :get, remote: true, class: 'form-search pull-right',
|
||||
'data-submit-onchange' => true do
|
||||
= text_field_tag :query, params[:query], class: 'input-medium search-query',
|
||||
placeholder: t('.search_placeholder')
|
||||
|
||||
.btn-group
|
||||
= link_to t('.new'), new_supplier_article_path(@supplier), remote: true, class: 'btn btn-primary'
|
||||
= link_to t('.edit_all'), edit_all_supplier_articles_path(@supplier), class: 'btn'
|
||||
= link_to t('.upload'), upload_supplier_articles_path(@supplier), class: 'btn'
|
||||
- if current_user.role_orders?
|
||||
= link_to t('.new_order'), new_order_path(supplier_id: @supplier), class: 'btn'
|
||||
|
||||
- unless @supplier.shared_supplier.nil?
|
||||
.btn-group
|
||||
= link_to '#', data: {toggle: 'dropdown'}, class: 'btn btn-success dropdown-toggle' do
|
||||
= t '.ext_db.title'
|
||||
%span.caret
|
||||
%ul.dropdown-menu
|
||||
%li= link_to t('.ext_db.import'), "#import", 'data-toggle-this' => '#import'
|
||||
%li= link_to t('.ext_db.sync'), sync_supplier_articles_path(@supplier), method: :post
|
||||
|
||||
.btn-group
|
||||
= link_to '#', data: {toggle: 'dropdown'}, class: 'btn dropdown-toggle' do
|
||||
= t '.change_supplier'
|
||||
%span.caret
|
||||
%ul.dropdown-menu
|
||||
- Supplier.undeleted.where.not(id: @supplier.id).order('suppliers.name ASC').each do |supplier|
|
||||
%li= link_to supplier.name, supplier_articles_path(supplier), tabindex: -1
|
||||
|
||||
- unless @supplier.shared_supplier.nil?
|
||||
#import.well.well-small(style="display:none;")
|
||||
= form_tag shared_supplier_articles_path(@supplier), method: :get, remote: true, class: 'form-search',
|
||||
'data-submit-onchange' => true do
|
||||
%h3= t '.import.title'
|
||||
= text_field_tag "q[name_cont_all]", "", class: 'input-medium search-query',
|
||||
placeholder: t('.import.placeholder')
|
||||
%label.checkbox
|
||||
= check_box_tag "q[origin_eq]", "REG", false
|
||||
= t '.import.restrict_region'
|
||||
#search_results.clearfix
|
||||
= link_to t('ui.close'), "#import", 'data-toggle-this' => '#import'
|
||||
|
||||
= form_tag update_selected_supplier_articles_path(@supplier), id: "articlesInListForm",
|
||||
'data-submit-onchange' => true do
|
||||
#table= render 'articles'
|
72
app/views/articles/index.html.haml
Normal file
72
app/views/articles/index.html.haml
Normal file
|
@ -0,0 +1,72 @@
|
|||
- title t('.title', supplier: @supplier.name, count: @supplier.articles.undeleted.count)
|
||||
|
||||
- content_for :actionbar do
|
||||
.btn-group
|
||||
= link_to '#', data: {toggle: 'dropdown'}, class: 'btn dropdown-toggle' do
|
||||
= t '.change_supplier'
|
||||
%span.caret
|
||||
%ul.dropdown-menu
|
||||
- Supplier.undeleted.where.not(id: @supplier.id).order('suppliers.name ASC').each do |supplier|
|
||||
%li= link_to supplier.name, supplier_articles_path(supplier), tabindex: -1
|
||||
|
||||
.well.well-small
|
||||
.btn-toolbar
|
||||
= form_tag supplier_articles_path(@supplier), method: :get, remote: true, class: 'form-search pull-right',
|
||||
'data-submit-onchange' => true do
|
||||
= text_field_tag :query, params[:query], class: 'input-medium search-query',
|
||||
placeholder: t('.search_placeholder')
|
||||
|
||||
- if @supplier.shared_supplier
|
||||
.btn-group
|
||||
= link_to t('.ext_db.import'), "#import", 'data-toggle-this' => '#import', class: 'btn btn-primary'
|
||||
= link_to t('.ext_db.sync'), sync_supplier_articles_path(@supplier), method: :post, class: 'btn btn-success'
|
||||
|
||||
.btn-group
|
||||
= link_to t('.new'), new_supplier_article_path(@supplier), remote: true, class: "btn #{'btn-primary' unless @supplier.shared_supplier}"
|
||||
= link_to t('.edit_all'), edit_all_supplier_articles_path(@supplier), class: 'btn'
|
||||
= link_to t('.upload'), upload_supplier_articles_path(@supplier), class: 'btn'
|
||||
- if current_user.role_orders?
|
||||
= link_to t('.new_order'), new_order_path(supplier_id: @supplier), class: 'btn'
|
||||
|
||||
- unless @supplier.shared_supplier.nil?
|
||||
#import.well.well-small(style="display:none;")
|
||||
= form_tag shared_supplier_articles_path(@supplier), method: :get, remote: true, class: 'form-search',
|
||||
'data-submit-onchange' => true do
|
||||
%h3{style: 'display: inline; vertical-align: middle; margin-right: 1em;'}= t('.import.title') + ' '
|
||||
= text_field_tag "q[name_cont_all]", "", class: 'input-medium search-query',
|
||||
placeholder: t('.import.placeholder')
|
||||
%label.checkbox
|
||||
= check_box_tag "q[origin_eq]", "REG", false
|
||||
= t '.import.restrict_region'
|
||||
.pull-right{style: 'line-height: 40px'}
|
||||
= label_tag :article_category_id, t('.import.category')
|
||||
= collection_select :article_category, :id, ArticleCategory.all, :id, :name,
|
||||
{include_blank: true}, {'data-ignore-onchange' => true}
|
||||
#search_results.clearfix
|
||||
= link_to t('ui.close'), "#import", 'data-toggle-this' => '#import', class: 'btn'
|
||||
|
||||
= form_tag update_selected_supplier_articles_path(@supplier), id: "articlesInListForm",
|
||||
'data-submit-onchange' => true do
|
||||
#table= render 'articles'
|
||||
|
||||
- content_for :javascript do
|
||||
:javascript
|
||||
// keep import button pressed when import section is shown
|
||||
$(document).on('touchclick', 'a[data-toggle-this=#import]', function() {
|
||||
var state = $('#import').is(':visible');
|
||||
$('.btn-toolbar a[data-toggle-this=#import]').toggleClass('active', !state);
|
||||
if (!state) {
|
||||
// also load articles when shown
|
||||
$('#import form').submit();
|
||||
// select category when form is shown, to avoid errors
|
||||
$('#import #article_category_id').val('');
|
||||
}
|
||||
});
|
||||
// propagate category select to article import
|
||||
// XXX quite a url hack
|
||||
$(document).on('touchclick', '#import .actions a[href]', function() {
|
||||
var category_id = $('#import #article_category_id').children(':selected').val();
|
||||
var url = $(this).attr('href');
|
||||
url = url.replace(/(&article_category_id=[0-9]*)?$/, '&article_category_id='+category_id);
|
||||
$(this).attr('href', url);
|
||||
});
|
|
@ -350,17 +350,18 @@ en:
|
|||
title_new: Add new article
|
||||
import_search_results:
|
||||
action_import: import
|
||||
already_imported: already imported
|
||||
action_edit_import: edit import
|
||||
already_imported: imported
|
||||
not_found: No articles found
|
||||
index:
|
||||
change_supplier: Change supplier ...
|
||||
edit_all: Edit all
|
||||
ext_db:
|
||||
import: Search/Import
|
||||
import: Import article
|
||||
sync: Synchronise
|
||||
title: External databank
|
||||
import:
|
||||
placeholder: Name ...
|
||||
category: Directly import into category
|
||||
placeholder: Search by name ...
|
||||
restrict_region: Restrict to region only
|
||||
title: Import article
|
||||
new: New article
|
||||
|
|
Loading…
Reference in a new issue