form_creation 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 974d303c9a62102409be1eab1a2fcbd3ee62bd00170b4dcc89373f538f17d0a7
4
- data.tar.gz: 9023f00c98f93bf278592c9fcaccb67fc8a72a089c3531c1389eae34d15f0ab0
3
+ metadata.gz: 66f198cf5b06375c2efe46483a4a34c8c09301908403e17f58e447650acf7e70
4
+ data.tar.gz: 86e4f431ee40a4227aaa964e6a7f873887c629bf9e8202949d482b87cc40ee77
5
5
  SHA512:
6
- metadata.gz: abfd98c2b22ebfe90d24372c8a3e0c1c5d135231566f260a2f1b857e5101fbf34f7bd2c0cc5945c10e1807e4616832c69c1636866236f02a135245e9860979aa
7
- data.tar.gz: 9eea73b477fb9f2af2254d8098c02d8c838811c3f990c5c0d7a7b04d02a7282e286c151491fd26d8ddfbb152315d98db1a5dc86aa0cc101c9337b8dc50d7a71c
6
+ metadata.gz: 897a48d113e90c7a1767de91cc74bc59ae2cb0f6c4d88466b98800a217b15e36ff84e99c444bd60ef3ddd7a1f9b5cbc48cf0644747b0677e663c50e4b0139295
7
+ data.tar.gz: 5ea2455fb874ad63fb634c4aa522f5923c6a13d61afc751a3c383c69e71756a26a5e5f2c373ebd83cd5bda3d9021c00d672bbfbb77c49a28d4fea4c24525dca9
@@ -1,29 +1,78 @@
1
1
  // Place all the behaviors and hooks related to the matching controller here.
2
2
  // All this logic will automatically be available in application.js.
3
-
4
- $(document).ready(function(){
5
- $("#new_post").validate({
6
- rules: {
7
- title: "required",
8
- description: "required",
9
- created_by: "required",
10
- },
11
- messages: {
12
- title: "Please enter title",
13
- description: "Please enter description",
14
- created_by: "Please enter create_by",
15
- },
16
- });
17
- $(".edit_post").validate({
18
- rules: {
19
- title: "required",
20
- description: "required",
21
- created_by: "required",
22
- },
23
- messages: {
24
- title: "Please enter title",
25
- description: "Please enter description",
26
- created_by: "Please enter create_by",
27
- },
28
- });
3
+ $(document).ready(function() {
4
+ // validations for new post
5
+ $("#new_post").validate({
6
+ rules: {
7
+ title: {
8
+ required: true,
9
+ maxlength: 30
10
+ },
11
+ description: "required",
12
+ created_by: {
13
+ required: true,
14
+ maxlength: 30
15
+ },
16
+ },
17
+ messages: {
18
+ title: {
19
+ required: "Please enter title",
20
+ maxlength: "Please enter no more than 30 characters."
21
+ },
22
+ description: "Please enter description",
23
+ created_by: {
24
+ required: "Please enter created_by",
25
+ maxlength: "Please enter no more than 30 characters."
26
+ },
27
+ },
28
+ });
29
+ // validations for edit post
30
+ $(".edit_post").validate({
31
+ rules: {
32
+ title: {
33
+ required: true,
34
+ maxlength: 30
35
+ },
36
+ description: "required",
37
+ created_by: {
38
+ required: true,
39
+ maxlength: 30
40
+ },
41
+ },
42
+ messages: {
43
+ title: {
44
+ required: "Please enter title",
45
+ maxlength: "Please enter no more than 30 characters."
46
+ },
47
+ description: "Please enter description",
48
+ created_by: {
49
+ required: "Please enter created_by",
50
+ maxlength: "Please enter no more than 30 characters."
51
+ },
52
+ },
53
+ });
54
+ // Reset modal new form
55
+ $(".close").click(function() {
56
+ $("#new_post")[0].reset();
57
+ var validator = $("#new_post").validate();
58
+ validator.resetForm();
59
+ });
60
+ // Reset modal edit form
61
+ $(".edit_close").click(function() {
62
+ $(".edit_post")[0].reset();
63
+ var validator = $(".edit_post").validate();
64
+ validator.resetForm();
65
+ });
66
+ // when click on body, reset modal new form
67
+ $('#add_post').on('hidden.bs.modal', function() {
68
+ $("#new_post")[0].reset();
69
+ var validator = $("#new_post").validate();
70
+ validator.resetForm();
71
+ });
72
+ // when click on body, reset modal edit form
73
+ $('.edit_post-form').on('hidden.bs.modal', function() {
74
+ $(".edit_post")[0].reset();
75
+ var validator = $(".edit_post").validate();
76
+ validator.resetForm();
77
+ });
29
78
  });
@@ -10,21 +10,40 @@
10
10
  border-radius: 3px;
11
11
  }
12
12
  .post-1 {
13
- width: 300px !important;
13
+ width: 500px !important;
14
14
  margin: 70px auto !important;
15
15
  border: 1px solid #ccc;
16
16
  padding: 32px;
17
17
  border-radius: 3px;
18
- box-shadow: 2px 2px #ccc;
18
+ box-shadow: 10px 10px 13px #ccc;
19
19
  background-color: #f9f8f8;
20
20
  }
21
21
  .error {
22
22
  color: red;
23
23
  font-size: 14px;
24
24
  }
25
- .fade:not(.show) {
26
- opacity: 0.8 !important;
27
- }
28
25
  .modal-content {
29
26
  margin-top: 145px;
30
27
  }
28
+ .post-details {
29
+ color: #c56b6b;
30
+ text-align: left;
31
+ }
32
+ .post-col {
33
+ float: left !important;
34
+ }
35
+ .back-btn {
36
+ text-align: center;
37
+ margin-top: 20px;
38
+ clear: both;
39
+ }
40
+ .post-content {
41
+ margin-top: 0px !important;
42
+ }
43
+ .save {
44
+ margin-top: 10px;
45
+ margin-bottom: 30px;
46
+ }
47
+ .save-btn {
48
+ width: 465px;
49
+ }
@@ -3,7 +3,8 @@ require_dependency "form_creation/application_controller"
3
3
  module FormCreation
4
4
  class PostsController < ApplicationController
5
5
  def index
6
- @posts = Post.order('id DESC')
6
+ @posts = Post.order('id DESC')
7
+ @post = Post.new
7
8
  end
8
9
 
9
10
  # GET method to get a Post by id
@@ -1,7 +1,7 @@
1
1
  module FormCreation
2
2
  class Post < ApplicationRecord
3
- # validates :title, presence: true
4
- # validates :description, presence: true
5
- # validates :created_by, presence: true
3
+ validates :title, presence: true
4
+ validates :description, presence: true
5
+ validates :created_by, presence: true
6
6
  end
7
7
  end
@@ -0,0 +1,12 @@
1
+ <div class="form-group">
2
+ <label>Title</label>
3
+ <%= f.text_field :title, class: "form-control", name: "title" %>
4
+ </div>
5
+ <div class="form-group">
6
+ <label>Description</label>
7
+ <%= f.text_area :description, class: "form-control", rows: "5", cols: "10", style: "resize:none;", name: 'description' %>
8
+ </div>
9
+ <div class="form-group">
10
+ <label>Created By</label>
11
+ <%= f.text_field :created_by, class: "form-control", name: "created_by" %>
12
+ </div>
@@ -1,3 +1,4 @@
1
+ <!-- Edit post form -->
1
2
  <div class="container post">
2
3
  <%= form_for @post, url: {action: :update} do |f| %>
3
4
  <div>
@@ -7,12 +8,12 @@
7
8
  <p>
8
9
  <%= "<div>#{@post.errors.full_messages.first}</div>".html_safe if @post.errors.any? %>
9
10
  <div class="form-group">
10
- <label>Title</label>
11
- <%= f.text_field :title, class: "form-control", name: "title" %>
11
+ <label>Title</label>
12
+ <%= f.text_field :title, class: "form-control", name: "title" %>
12
13
  </div>
13
14
  <div class="form-group">
14
- <label>Description</label>
15
- <%= f.text_area :description, class: "form-control", rows: "5", cols: "10", style: "resize:none;", name: 'description' %>
15
+ <label>Description</label>
16
+ <%= f.text_area :description, class: "form-control", rows: "5", cols: "10", style: "resize:none;", name: 'description' %>
16
17
  </div>
17
18
  <div class="form-group">
18
19
  <label>Created By</label>
@@ -1,7 +1,28 @@
1
+ <!-- display all posts -->
1
2
  <div class="container" style="margin-top: 70px;">
2
3
  <h3>Posts</h3>
3
4
  <div style="margin-bottom: 10px;">
4
- <%= link_to 'Add Post', new_post_path, class: "btn btn-success" %>
5
+ <%= button_tag "Add <span class=\"fa fa-plus\"></span>".html_safe, class: "btn btn-success btn-sm", "data-toggle" => "modal", "data-target" => "#add_post" %>
6
+ <div class="modal fade" id="add_post" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
7
+ <div class="modal-dialog" role="document">
8
+ <div class="modal-content post-content">
9
+ <div class="modal-header">
10
+ <h3 class="post-details modal-title" id="exampleModalLabel">Add Post</h3>
11
+ <%= button_tag "<span aria-hidden=\"true\">&times;</span>".html_safe, class: "close close-2", "data-dismiss" => "modal", "aria-label" => "Close" %>
12
+ </div>
13
+ <div class="modal-body">
14
+ <%= form_for @post, url: {action: :create} do |f| %>
15
+ <div>
16
+ <%= render :partial => "form", :locals => {:f => f} %>
17
+ </div>
18
+ <div class="save">
19
+ <%= f.submit 'Create Post', class: "btn btn-primary save-btn", id: "sub" %>
20
+ </div>
21
+ <% end %>
22
+ </div>
23
+ </div>
24
+ </div>
25
+ </div>
5
26
  </div>
6
27
  <table class="table table-striped">
7
28
  <thead>
@@ -19,25 +40,68 @@
19
40
  <td><%= p.description %></td>
20
41
  <td><%= p.created_by %></td>
21
42
  <td>
22
- <%= link_to 'Show', post_path(p), class: "btn btn-info" %>
23
- <%= link_to 'Edit', edit_post_path(p), class: "btn btn-warning"%>
24
- <button type="button" class="btn btn-danger" data-toggle="modal" data-target="#post-<%= p.id %>">
25
- Delete
26
- </button>
43
+ <%= button_tag "<span class=\"fa fa-eye\"></span>".html_safe, class: "btn btn-info btn-sm", "data-toggle" => "modal", "data-target" => "#show_post-#{p.id}" %>
44
+ <div class="modal fade" id="show_post-<%= p.id %>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
45
+ <div class="modal-dialog" role="document">
46
+ <div class="modal-content">
47
+ <div class="modal-header">
48
+ <h3 class="post-details modal-title" id="exampleModalLabel">Post Details</h3>
49
+ <%= button_tag "<span aria-hidden=\"true\">&times;</span>".html_safe, class: "close close-2", "data-dismiss" => "modal", "aria-label" => "Close" %>
50
+ </div>
51
+ <div class="modal-body">
52
+ <div class="row">
53
+ <div class="col-md-4 "><b>Title:</b></div>
54
+ <div class="col-md-8"><%= p.title %></div>
55
+ </div>
56
+ <div class="row">
57
+ <div class="col-md-4 "><b>Description:</b></div>
58
+ <div class="col-md-8 "><%= p.description %></div>
59
+ </div>
60
+ <div class="row">
61
+ <div class="col-md-4 "><b>Created By:</b></div>
62
+ <div class="col-md-8"><%= p.created_by %></div>
63
+ </div>
64
+ </div>
65
+ <div class="modal-footer">
66
+ <%= button_tag "Close", class: "btn btn-secondary", "data-dismiss" => "modal" %>
67
+ </div>
68
+ </div>
69
+ </div>
70
+ </div>
71
+ <%= button_tag "<span class=\"fa fa-edit\"></span>".html_safe, class: "btn btn-warning btn-sm", "data-toggle" => "modal", "data-target" => "#edit_post-#{p.id}" %>
72
+ <div class="modal fade edit_post-form" id="edit_post-<%= p.id %>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
73
+ <div class="modal-dialog" role="document">
74
+ <div class="modal-content post-content">
75
+ <div class="modal-header">
76
+ <h3 class="post-details modal-title" id="exampleModalLabel">Update Post</h3>
77
+ <%= button_tag "<span aria-hidden=\"true\">&times;</span>".html_safe, class: "close edit_close", "data-dismiss" => "modal", "aria-label" => "Close" %>
78
+ </div>
79
+ <div class="modal-body">
80
+ <%= form_for p, url: post_path(p), method: :put do |f| %>
81
+ <div>
82
+ <%= render :partial => "form", :locals => {:f => f} %>
83
+ </div>
84
+ <div class="save">
85
+ <%= f.submit 'Update Post', class: "btn btn-primary save-btn", id: "sub" %>
86
+ </div>
87
+ <% end %>
88
+ </div>
89
+ </div>
90
+ </div>
91
+ </div>
92
+ <%= button_tag "<span class=\"fa fa-trash\"></span>".html_safe, class: "btn btn-danger btn-sm", "data-toggle" => "modal", "data-target" => "#post-#{p.id}" %>
27
93
  <div class="modal fade" id="post-<%= p.id %>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
28
94
  <div class="modal-dialog" role="document">
29
95
  <div class="modal-content">
30
96
  <div class="modal-header">
31
- <h5 class="modal-title" id="exampleModalLabel">Delete</h5>
32
- <button type="button" class="close" data-dismiss="modal" aria-label="Close">
33
- <span aria-hidden="true">&times;</span>
34
- </button>
97
+ <h3 class="modal-title" id="exampleModalLabel">Delete</h3>
98
+ <%= button_tag "<span aria-hidden=\"true\">&times;</span>".html_safe, class: "close close-2", "data-dismiss" => "modal", "aria-label" => "Close" %>
35
99
  </div>
36
100
  <div class="modal-body">
37
101
  Are you sure?
38
102
  </div>
39
103
  <div class="modal-footer">
40
- <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
104
+ <%= button_tag "Close", class: "btn btn-secondary", "data-dismiss" => "modal" %>
41
105
  <%= link_to 'Delete', post_path(p), method: :delete, class: "btn btn-danger" %>
42
106
  </div>
43
107
  </div>
@@ -47,4 +111,4 @@
47
111
  <% end %>
48
112
  </tbody>
49
113
  </table>
50
- </div>
114
+ </div>
@@ -1,3 +1,4 @@
1
+ <!-- Create a post -->
1
2
  <div class="container post">
2
3
  <%= form_for @post, url: {action: :create} do |f| %>
3
4
  <div>
@@ -1,18 +1,19 @@
1
+ <!-- Show post based on user id -->
1
2
  <div class="container post-1">
2
- <h3>Post Details</h3>
3
- <div>
4
- <label><b>Title:</b></label>
5
- <%= @post.title %>
3
+ <h3 class="post-details">Post Details</h3>
4
+ <div class="row">
5
+ <div class="col-md-4 "><b>Title:</b></div>
6
+ <div class="col-md-8"><%= @post.title %></div>
6
7
  </div>
7
- <div>
8
- <label><b>Description:</b></label>
9
- <%= @post.description %>
8
+ <div class="row">
9
+ <div class="col-md-4 "><b>Description:</b></div>
10
+ <div class="col-md-8 "><%= @post.description %></div>
10
11
  </div>
11
- <div>
12
- <label><b>Created By:</b></label>
13
- <%= @post.created_by %>
12
+ <div class="row">
13
+ <div class="col-md-4 "><b>Created By:</b></div>
14
+ <div class="col-md-8"><%= @post.created_by %></div>
14
15
  </div>
15
- <div style="text-align: center;">
16
+ <div class="back-btn">
16
17
  <%= link_to 'Back', posts_path, class: "btn btn-info" %>
17
18
  </div>
18
- </div>
19
+ </div>
@@ -7,17 +7,15 @@
7
7
  <%= stylesheet_link_tag "form_creation/application", media: "all" %>
8
8
  <%= javascript_include_tag "form_creation/application" %>
9
9
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
10
- <!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.1/jquery.validate.min.js"></script>
11
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
12
- <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script> -->
13
10
  <script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
14
11
  <script src="https://cdn.jsdelivr.net/jquery.validation/1.16.0/jquery.validate.min.js"></script>
15
12
  <script src="https://cdn.jsdelivr.net/jquery.validation/1.16.0/additional-methods.min.js"></script>
16
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
13
+ <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
14
+ <script src='https://kit.fontawesome.com/a076d05399.js'></script>
15
+ <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.0/css/all.css" integrity="sha384-lZN37f5QGtY3VHgisS14W3ExzMWZxybE1SJSEsQp9S+oqd12jhcu+A56Ebc1zFSJ" crossorigin="anonymous">
16
+
17
17
  </head>
18
18
  <body>
19
-
20
- <%= yield %>
21
-
19
+ <%= yield %>
22
20
  </body>
23
21
  </html>
data/config/routes.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  FormCreation::Engine.routes.draw do
2
+ #Routes for posts
2
3
  resources :posts
3
4
  end
@@ -1,3 +1,3 @@
1
1
  module FormCreation
2
- VERSION = '0.1.5'
2
+ VERSION = '0.1.6'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: form_creation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - madhubabu-nyros
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-15 00:00:00.000000000 Z
11
+ date: 2019-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -81,6 +81,7 @@ files:
81
81
  - app/mailers/form_creation/application_mailer.rb
82
82
  - app/models/form_creation/application_record.rb
83
83
  - app/models/form_creation/post.rb
84
+ - app/views/form_creation/posts/_form.html.erb
84
85
  - app/views/form_creation/posts/create.html.erb
85
86
  - app/views/form_creation/posts/destroy.html.erb
86
87
  - app/views/form_creation/posts/edit.html.erb