Skip to content

Commit

Permalink
Run validations before signing
Browse files Browse the repository at this point in the history
  • Loading branch information
luciajanikova committed Dec 6, 2023
1 parent 7f701e2 commit ee4ec5d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
15 changes: 8 additions & 7 deletions app/components/message_draft_body_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@
<% if @message.not_yet_submitted? && @message.form&.signable? %>
<div class="gap-2 p-2 border-t-0 border-r-0 border-b-0 border-l-0 border-gray-200">
<%= content_tag(:div,
{
"data-controller": "autogram",
"data-autogram-object-id": @message.form.id,
"data-autogram-message-id": @message.id,
"data-autogram-object-path": message_message_object_path(@message.id, @message.form.id),
"data-autogram-authenticity-token": form_authenticity_token
}) do %>
{
"data-turbo-frame": "_top",
"data-controller": "autogram",
"data-autogram-object-id": @message.form.id,
"data-autogram-message-id": @message.id,
"data-autogram-object-path": message_message_object_path(@message.id, @message.form.id),
"data-autogram-authenticity-token": form_authenticity_token
}) do %>
<button data-action="click->autogram#signSingleFile" class="flex justify-strech items-start self-stretch flex-grow-0 flex-shrink-0 gap-2 p-6 text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-3.5 py-2.5 dark:bg-blue-600 dark:hover:bg-blue-700 focus:outline-none dark:focus:ring-blue-800">
Podpísať
</button>
Expand Down
9 changes: 5 additions & 4 deletions app/controllers/message_objects_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
class MessageObjectsController < ApplicationController
before_action :set_message_object, except: :create
before_action :set_message, only: [:create, :update, :destroy]
before_action :set_message, only: [:create, :update, :destroy, :signing_data]

def create
authorize @message

MessageObject.create_message_objects(@message, params[:attachments])

render partial: "list"
render partial: 'list'
end

def update
Expand All @@ -30,15 +30,16 @@ def download
def signing_data
authorize @message_object

head :no_content unless @message_object.content.present?
head :no_content and return unless @message_object.content.present?
render template: 'message_drafts/update_body' and return unless @message.valid?(:validate_data)
end

def destroy
authorize @message_object

@message_object.destroy

render partial: "list"
render partial: 'list'
end

private
Expand Down
8 changes: 4 additions & 4 deletions app/javascript/controllers/autogram_controller.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { Controller } from "@hotwired/stimulus"
import { patch } from '@rails/request.js'
import { get, patch } from '@rails/request.js'

export default class extends Controller {

async sign(messageObjectPath, that, batchId = null) {
return new Promise((resolve, reject) => {
fetch(`${messageObjectPath}/signing_data.json`)
get(`${messageObjectPath}/signing_data`, { responseKind: "*/*" })
.then(function (response) {
// TODO handle login if expired session

if (response.status === 204) {
alert("Vyplňte správu");
}
else {
return response.json();
else if (response.contentType === 'application/json') {
return response.json;
}
}).then(async function (messageObjectData) {
if (!messageObjectData) {
Expand Down

0 comments on commit ee4ec5d

Please sign in to comment.