Reduce duplication between the project and group label forms

This commit is contained in:
Douglas Barbosa Alexandre 2016-10-11 00:04:15 -03:00
parent 00e3c2e00f
commit f98e97fe78
7 changed files with 6 additions and 38 deletions

View file

@ -21,6 +21,7 @@ class Groups::LabelsController < Groups::ApplicationController
def new def new
@label = @group.labels.new @label = @group.labels.new
@previous_labels_path = previous_labels_path
end end
def create def create

View file

@ -1,33 +0,0 @@
= form_for @label, as: :label, url: url, html: { class: 'form-horizontal label-form js-quick-submit js-requires-input' } do |f|
= form_errors(@label)
.form-group
= f.label :title, class: 'control-label'
.col-sm-10
= f.text_field :title, class: "form-control", required: true, autofocus: true
.form-group
= f.label :description, class: 'control-label'
.col-sm-10
= f.text_field :description, class: "form-control js-quick-submit"
.form-group
= f.label :color, "Background color", class: 'control-label'
.col-sm-10
.input-group
.input-group-addon.label-color-preview &nbsp;
= f.color_field :color, class: "form-control"
.help-block
Choose any color.
%br
Or you can choose one of suggested colors below
.suggest-colors
- suggested_colors.each do |color|
= link_to '#', style: "background-color: #{color}", data: { color: color } do
&nbsp;
.form-actions
- if @label.persisted?
= f.submit 'Save changes', class: 'btn btn-save js-save-button'
- else
= f.submit 'Create Label', class: 'btn btn-create js-save-button'
= link_to 'Cancel', @previous_labels_path, class: 'btn btn-cancel'

View file

@ -4,4 +4,4 @@
Edit Label Edit Label
%hr %hr
= render 'form', url: group_label_path(@group, @label) = render 'shared/labels/form', url: group_label_path(@group, @label), back_path: @previous_labels_path

View file

@ -5,4 +5,4 @@
New Label New Label
%hr %hr
= render 'form', url: group_labels_path = render 'shared/labels/form', url: group_labels_path, back_path: @previous_labels_path

View file

@ -6,4 +6,4 @@
%h3.page-title %h3.page-title
Edit Label Edit Label
%hr %hr
= render 'form', url: namespace_project_label_path(@project.namespace.becomes(Namespace), @project, @label) = render 'shared/labels/form', url: namespace_project_label_path(@project.namespace.becomes(Namespace), @project, @label), back_path: namespace_project_labels_path(@project.namespace, @project)

View file

@ -6,4 +6,4 @@
%h3.page-title %h3.page-title
New Label New Label
%hr %hr
= render 'form', url: namespace_project_labels_path(@project.namespace.becomes(Namespace), @project) = render 'shared/labels/form', url: namespace_project_labels_path(@project.namespace.becomes(Namespace), @project), back_path: namespace_project_labels_path(@project.namespace, @project)

View file

@ -30,4 +30,4 @@
= f.submit 'Save changes', class: 'btn btn-save js-save-button' = f.submit 'Save changes', class: 'btn btn-save js-save-button'
- else - else
= f.submit 'Create Label', class: 'btn btn-create js-save-button' = f.submit 'Create Label', class: 'btn btn-create js-save-button'
= link_to 'Cancel', namespace_project_labels_path(@project.namespace, @project), class: 'btn btn-cancel' = link_to 'Cancel', back_path, class: 'btn btn-cancel'