mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-11-10 08:21:37 +08:00
Fix edit mode for File and Text
This commit is contained in:
parent
9e0d0d74ea
commit
24acf1f84b
9 changed files with 67 additions and 23 deletions
|
|
@ -5,7 +5,7 @@ var RepositoryColumns = (function() {
|
||||||
|
|
||||||
function initColumnTypeSelector() {
|
function initColumnTypeSelector() {
|
||||||
var $manageModal = $(manageModal);
|
var $manageModal = $(manageModal);
|
||||||
$manageModal.off('click', '#repository-column-data-type').on('click', '#repository-column-data-type', function() {
|
$manageModal.off('change', '#repository-column-data-type').on('change', '#repository-column-data-type', function() {
|
||||||
$('.column-type').hide();
|
$('.column-type').hide();
|
||||||
$('[data-column-type="' + $(this).val() + '"]').show();
|
$('[data-column-type="' + $(this).val() + '"]').show();
|
||||||
});
|
});
|
||||||
|
|
@ -75,6 +75,11 @@ var RepositoryColumns = (function() {
|
||||||
$('[data-attr="no-columns"]').remove();
|
$('[data-attr="no-columns"]').remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateListItem(column) {
|
||||||
|
var name = column.attributes.name;
|
||||||
|
$('li[data-id=' + column.id + ']').find('span').first().text(name);
|
||||||
|
}
|
||||||
|
|
||||||
function initCreateSubmitAction() {
|
function initCreateSubmitAction() {
|
||||||
var $manageModal = $(manageModal);
|
var $manageModal = $(manageModal);
|
||||||
$manageModal.off('click', '#new-repo-column-submit').on('click', '#new-repo-column-submit', function() {
|
$manageModal.off('click', '#new-repo-column-submit').on('click', '#new-repo-column-submit', function() {
|
||||||
|
|
@ -93,8 +98,23 @@ var RepositoryColumns = (function() {
|
||||||
|
|
||||||
function initEditSubmitAction() {
|
function initEditSubmitAction() {
|
||||||
var $manageModal = $(manageModal);
|
var $manageModal = $(manageModal);
|
||||||
$manageModal.off('click', '#new-repo-column-submit').on('click', '#new-repo-column-submit', function() {
|
$manageModal.off('click', '#update-repo-column-submit').on('click', '#update-repo-column-submit', function() {
|
||||||
// TODO
|
var url = $('#repository-column-data-type').find(':selected').data('edit-url');
|
||||||
|
var params = { repository_column: { name: $('#repository-column-name').val() } };
|
||||||
|
$.ajax({
|
||||||
|
url: url,
|
||||||
|
type: 'PUT',
|
||||||
|
data: params,
|
||||||
|
success: function(result) {
|
||||||
|
var data = result.data;
|
||||||
|
updateListItem(data);
|
||||||
|
HelperModule.flashAlertMsg(data.attributes.message, 'success');
|
||||||
|
$manageModal.modal('hide');
|
||||||
|
},
|
||||||
|
error: function(error) {
|
||||||
|
$('#new-repository-column').renderFormErrors('repository_column', error.responseJSON.repository_column, true);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -110,6 +130,9 @@ var RepositoryColumns = (function() {
|
||||||
|
|
||||||
if (button.data('action') === 'new') {
|
if (button.data('action') === 'new') {
|
||||||
$('[data-column-type="RepositoryTextValue"]').show();
|
$('[data-column-type="RepositoryTextValue"]').show();
|
||||||
|
$('#new-repo-column-submit').show();
|
||||||
|
} else {
|
||||||
|
$('#update-repo-column-submit').show();
|
||||||
}
|
}
|
||||||
}).fail(function() {
|
}).fail(function() {
|
||||||
HelperModule.flashAlertMsg(I18n.t('libraries.repository_columns.no_permissions'), 'danger');
|
HelperModule.flashAlertMsg(I18n.t('libraries.repository_columns.no_permissions'), 'danger');
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ module RepositoryColumns
|
||||||
params: repository_column_params)
|
params: repository_column_params)
|
||||||
|
|
||||||
if service.succeed?
|
if service.succeed?
|
||||||
render json: service.column, status: :created
|
render json: service.column, status: :created, creating: true
|
||||||
else
|
else
|
||||||
render json: service.errors, status: :unprocessable_entity
|
render json: service.errors, status: :unprocessable_entity
|
||||||
end
|
end
|
||||||
|
|
@ -28,7 +28,7 @@ module RepositoryColumns
|
||||||
params: repository_column_params)
|
params: repository_column_params)
|
||||||
|
|
||||||
if service.succeed?
|
if service.succeed?
|
||||||
render json: service.column, status: :ok
|
render json: service.column, status: :ok, updating: true
|
||||||
else
|
else
|
||||||
render json: service.errors, status: :unprocessable_entity
|
render json: service.errors, status: :unprocessable_entity
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -14,9 +14,7 @@ module RepositoryColumns
|
||||||
params: repository_column_params)
|
params: repository_column_params)
|
||||||
|
|
||||||
if service.succeed?
|
if service.succeed?
|
||||||
render json: service.column,
|
render json: service.column, status: :created, creating: true
|
||||||
serializer: RepositoryColumnSerializer,
|
|
||||||
status: :created
|
|
||||||
else
|
else
|
||||||
render json: service.errors, status: :unprocessable_entity
|
render json: service.errors, status: :unprocessable_entity
|
||||||
end
|
end
|
||||||
|
|
@ -30,7 +28,7 @@ module RepositoryColumns
|
||||||
params: repository_column_params)
|
params: repository_column_params)
|
||||||
|
|
||||||
if service.succeed?
|
if service.succeed?
|
||||||
render json: service.column, status: :ok
|
render json: service.column, status: :ok, editing: true
|
||||||
else
|
else
|
||||||
render json: service.errors, status: :unprocessable_entity
|
render json: service.errors, status: :unprocessable_entity
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,11 @@ class RepositoryColumnSerializer < ActiveModel::Serializer
|
||||||
attributes :id, :name, :message, :edit_html_url, :update_url, :destroy_html_url
|
attributes :id, :name, :message, :edit_html_url, :update_url, :destroy_html_url
|
||||||
|
|
||||||
def message
|
def message
|
||||||
I18n.t('libraries.repository_columns.create.success_flash', name: object.name)
|
if instance_options[:creating]
|
||||||
|
I18n.t('libraries.repository_columns.create.success_flash', name: object.name)
|
||||||
|
elsif instance_options[:editing]
|
||||||
|
I18n.t('libraries.repository_columns.update.success_flash', name: object.name)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit_html_url
|
def edit_html_url
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
class="form-control"
|
class="form-control"
|
||||||
type="text"
|
type="text"
|
||||||
name="repository_column[name]"
|
name="repository_column[name]"
|
||||||
id="repository-column-name">
|
id="repository-column-name" value="<%= @repository_column.name unless @repository_column.new_record? %>">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
|
@ -29,17 +29,30 @@
|
||||||
<%= t('libraries.manange_modal_column.colum_type') %>
|
<%= t('libraries.manange_modal_column.colum_type') %>
|
||||||
</label>
|
</label>
|
||||||
<div class="col-sm-9">
|
<div class="col-sm-9">
|
||||||
<select class="form-control" name="repository_column[data_type]" id="repository-column-data-type">
|
<select class="form-control" name="repository_column[data_type]" id="repository-column-data-type"
|
||||||
<option data-create-url="<%= repository_repository_columns_text_columns_path(@repository) %>" value="RepositoryTextValue">
|
<%= 'disabled' unless @repository_column.new_record? %>>
|
||||||
|
<option data-create-url="<%= repository_repository_columns_text_columns_path(@repository) %>"
|
||||||
|
data-edit-url="<%= repository_repository_columns_text_column_path(@repository, @repository_column) unless @repository_column.new_record? %>"
|
||||||
|
value="RepositoryTextValue"
|
||||||
|
<%= 'selected' if @repository_column.RepositoryTextValue? %> >
|
||||||
<%= t('libraries.manange_modal_column.select.repository_text_value') %>
|
<%= t('libraries.manange_modal_column.select.repository_text_value') %>
|
||||||
</option>
|
</option>
|
||||||
<option data-create-url="<%= repository_repository_columns_date_columns_path(@repository) %>" value="RepositoryDateValue">
|
<option data-create-url="<%= repository_repository_columns_status_columns_path(@repository) %>"
|
||||||
<%= t('libraries.manange_modal_column.select.repository_date_value') %>
|
data-edit-url="<%= repository_repository_columns_status_column_path(@repository, @repository_column) unless @repository_column.new_record? %>"
|
||||||
|
value="RepositoryStatusValue"
|
||||||
|
<%= 'selected' if @repository_column.RepositoryStatusValue? %> >
|
||||||
|
<%= t('libraries.manange_modal_column.select.repository_status_value') %>
|
||||||
</option>
|
</option>
|
||||||
<option data-create-url="<%= repository_repository_columns_list_columns_path(@repository) %>" value="RepositoryListValue">
|
<option data-create-url="<%= repository_repository_columns_list_columns_path(@repository) %>"
|
||||||
|
data-edit-url="<%= repository_repository_columns_list_column_path(@repository, @repository_column) unless @repository_column.new_record? %>"
|
||||||
|
value="RepositoryListValue"
|
||||||
|
<%= 'selected' if @repository_column.RepositoryListValue? %> >
|
||||||
<%= t('libraries.manange_modal_column.select.repository_list_value') %>
|
<%= t('libraries.manange_modal_column.select.repository_list_value') %>
|
||||||
</option>
|
</option>
|
||||||
<option data-create-url="<%= repository_repository_columns_asset_columns_path(@repository) %>" value="RepositoryAssetValue">
|
<option data-create-url="<%= repository_repository_columns_asset_columns_path(@repository) %>"
|
||||||
|
data-edit-url="<%= repository_repository_columns_asset_column_path(@repository, @repository_column) unless @repository_column.new_record? %>"
|
||||||
|
value="RepositoryAssetValue"
|
||||||
|
<%= 'selected' if @repository_column.RepositoryAssetValue? %> >
|
||||||
<%= t('libraries.manange_modal_column.select.repository_asset_value') %>
|
<%= t('libraries.manange_modal_column.select.repository_asset_value') %>
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
@ -56,13 +69,16 @@
|
||||||
<span style="display: none" class="column-type" data-column-type="RepositoryListValue">
|
<span style="display: none" class="column-type" data-column-type="RepositoryListValue">
|
||||||
<%= render partial: "repository_columns/manage_column_partials/list.html.erb" %>
|
<%= render partial: "repository_columns/manage_column_partials/list.html.erb" %>
|
||||||
</span>
|
</span>
|
||||||
<span style="display: none" class="column-type" data-column-type="RepositoryDateValue">
|
<span style="display: none" class="column-type" data-column-type="RepositoryStatusValue">
|
||||||
<%= render partial: "repository_columns/manage_column_partials/date.html.erb" %>
|
<%= render partial: "repository_columns/manage_column_partials/status.html.erb" %>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button id="new-repo-column-submit" class="btn btn-success" data-action="save">
|
<button id="new-repo-column-submit" class="btn btn-success" data-action="save" style="display: none;">
|
||||||
<%= t("libraries.manange_modal_column.new.button") %>
|
<%= t("libraries.manange_modal_column.new.button") %>
|
||||||
</button>
|
</button>
|
||||||
|
<button id="update-repo-column-submit" class="btn btn-success" data-action="save" style="display: none;">
|
||||||
|
<%= t("libraries.manange_modal_column.edit.button") %>
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
<%= 'asset-test' %>
|
<%# TO DO: add mandatory checkbox %>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
status
|
||||||
|
|
@ -1135,6 +1135,7 @@ en:
|
||||||
select:
|
select:
|
||||||
repository_text_value: "Text"
|
repository_text_value: "Text"
|
||||||
repository_date_value: "Date"
|
repository_date_value: "Date"
|
||||||
|
repository_status_value: "Status"
|
||||||
repository_list_value: "Dropdown"
|
repository_list_value: "Dropdown"
|
||||||
repository_asset_value: "File"
|
repository_asset_value: "File"
|
||||||
new:
|
new:
|
||||||
|
|
@ -1142,6 +1143,7 @@ en:
|
||||||
button: "Save column"
|
button: "Save column"
|
||||||
edit:
|
edit:
|
||||||
title: "Edit %{name} Column"
|
title: "Edit %{name} Column"
|
||||||
|
button: "Update column"
|
||||||
|
|
||||||
repository_columns:
|
repository_columns:
|
||||||
head_title: '%{repository} | Manage Columns'
|
head_title: '%{repository} | Manage Columns'
|
||||||
|
|
|
||||||
|
|
@ -182,8 +182,8 @@ ALTER SEQUENCE public.activities_id_seq OWNED BY public.activities.id;
|
||||||
CREATE TABLE public.ar_internal_metadata (
|
CREATE TABLE public.ar_internal_metadata (
|
||||||
key character varying NOT NULL,
|
key character varying NOT NULL,
|
||||||
value character varying,
|
value character varying,
|
||||||
created_at timestamp(6) without time zone NOT NULL,
|
created_at timestamp without time zone NOT NULL,
|
||||||
updated_at timestamp(6) without time zone NOT NULL
|
updated_at timestamp without time zone NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue