kablam 0.2.4 → 0.2.5

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: 54eb6a0722a2f5d9f8edfe00c14a6c336c06619dcbc7c0bf6ff7b13700de34fa
4
- data.tar.gz: 82ef1dec52bf58eb3ad65d30abc6745ddd2079469fbfa27968666b5bbe421d53
3
+ metadata.gz: ea5aa8b0bb18d19bf0fb27248b0280fc1defc81541116db1c8f20ae78b6dcbbe
4
+ data.tar.gz: 608717219ca9f67c3bbaa551353c28d6804b6b0d172cf4ccc0980919a918369d
5
5
  SHA512:
6
- metadata.gz: f8f2b47c6f5067ca9438916e45fc0256f3fdacd1988503899c7fe61b9c83e36bc026f5aa914a52cb862cc93b70df9e9b0ecceb4061f84bbd4562a3a700bcd9cd
7
- data.tar.gz: f8d3c20d51c13387f2fc3f37d9de8d88b301ee753371160208f55e0ed92240c30cfe7e871c449f3e3181193523e04a411e8306648cfa141da090640fce70aecf
6
+ metadata.gz: 60958bb2d96a09fd523784bb4332f039926de3f3e4785ec8619cc46fe531b10d035681c10d7c20ee189f430e864614c41af759b3f398826bf51e170bcb6fe503
7
+ data.tar.gz: abe3ce049c4a68f68a14c1610c5d78bc52efc9a9e41d112f0fbbc12d7f0462371b1893ceaf270dbb710379de533962dd1f6575fb9a104acb53842c4bf7514558
@@ -6,164 +6,38 @@ function AjaxRequest() {
6
6
  // Instance properties
7
7
  // -------------------
8
8
 
9
- /**
10
- * Timeout period (in ms) until an async request will be aborted, and
11
- * the onTimeout function will be called
12
- */
13
9
  req.timeout = null;
14
-
15
- /**
16
- * Since some browsers cache GET requests via XMLHttpRequest, an
17
- * additional parameter called AjaxRequestUniqueId will be added to
18
- * the request URI with a unique numeric value appended so that the requested
19
- * URL will not be cached.
20
- */
21
10
  req.generateUniqueUrl = true;
22
-
23
- /**
24
- * The url that the request will be made to, which defaults to the current
25
- * url of the window
26
- */
27
11
  req.url = window.location.href;
28
-
29
- /**
30
- * The method of the request, either GET (default), POST, or HEAD
31
- */
32
12
  req.method = "GET";
33
-
34
- /**
35
- * Whether or not the request will be asynchronous. In general, synchronous
36
- * requests should not be used so this should rarely be changed from true
37
- */
38
13
  req.async = true;
39
-
40
- /**
41
- * The username used to access the URL
42
- */
43
14
  req.username = null;
44
-
45
- /**
46
- * The password used to access the URL
47
- */
48
15
  req.password = null;
49
-
50
- /**
51
- * The parameters is an object holding name/value pairs which will be
52
- * added to the url for a GET request or the request content for a POST request
53
- */
54
16
  req.parameters = new Object();
55
-
56
- /**
57
- * The sequential index number of this request, updated internally
58
- */
59
17
  req.requestIndex = AjaxRequest.numAjaxRequests++;
60
-
61
- /**
62
- * Indicates whether a response has been received yet from the server
63
- */
64
18
  req.responseReceived = false;
65
-
66
- /**
67
- * The name of the group that this request belongs to, for activity
68
- * monitoring purposes
69
- */
70
19
  req.groupName = null;
71
-
72
- /**
73
- * The query string to be added to the end of a GET request, in proper
74
- * URIEncoded format
75
- */
76
20
  req.queryString = "";
77
-
78
- /**
79
- * After a response has been received, this will hold the text contents of
80
- * the response - even in case of error
81
- */
82
21
  req.responseText = null;
83
-
84
- /**
85
- * After a response has been received, this will hold the XML content
86
- */
87
22
  req.responseXML = null;
88
-
89
- /**
90
- * After a response has been received, this will hold the status code of
91
- * the response as returned by the server.
92
- */
93
23
  req.status = null;
94
-
95
- /**
96
- * After a response has been received, this will hold the text description
97
- * of the response code
98
- */
99
24
  req.statusText = null;
100
-
101
- /**
102
- * An internal flag to indicate whether the request has been aborted
103
- */
104
25
  req.aborted = false;
105
-
106
- /**
107
- * The XMLHttpRequest object used internally
108
- */
109
26
  req.xmlHttpRequest = null;
110
27
 
111
28
  // --------------
112
29
  // Event handlers
113
30
  // --------------
114
31
 
115
- /**
116
- * If a timeout period is set, and it is reached before a response is
117
- * received, a function reference assigned to onTimeout will be called
118
- */
119
32
  req.onTimeout = null;
120
-
121
- /**
122
- * A function reference assigned will be called when readyState=1
123
- */
124
33
  req.onLoading = null;
125
-
126
- /**
127
- * A function reference assigned will be called when readyState=2
128
- */
129
34
  req.onLoaded = null;
130
-
131
- /**
132
- * A function reference assigned will be called when readyState=3
133
- */
134
35
  req.onInteractive = null;
135
-
136
- /**
137
- * A function reference assigned will be called when readyState=4
138
- */
139
36
  req.onComplete = null;
140
-
141
- /**
142
- * A function reference assigned will be called after onComplete, if
143
- * the statusCode=200
144
- */
145
37
  req.onSuccess = null;
146
-
147
- /**
148
- * A function reference assigned will be called after onComplete, if
149
- * the statusCode != 200
150
- */
151
38
  req.onError = null;
152
-
153
- /**
154
- * If this request has a group name, this function reference will be called
155
- * and passed the group name if this is the first request in the group to
156
- * become active
157
- */
158
39
  req.onGroupBegin = null;
159
-
160
- /**
161
- * If this request has a group name, and this request is the last request
162
- * in the group to complete, this function reference will be called
163
- */
164
40
  req.onGroupEnd = null;
165
-
166
- // Get the XMLHttpRequest object itself
167
41
  req.xmlHttpRequest = AjaxRequest.getXmlHttpRequest();
168
42
  if (req.xmlHttpRequest==null) { return null; }
169
43
 
@@ -182,9 +56,6 @@ function AjaxRequest() {
182
56
  // ---------------------------------------------------------------------------
183
57
  // Internal event handlers that fire, and in turn fire the user event handlers
184
58
  // ---------------------------------------------------------------------------
185
- // Flags to keep track if each event has been handled, in case of
186
- // multiple calls (some browsers may call the onreadystatechange
187
- // multiple times for the same state)
188
59
  req.onLoadingInternalHandled = false;
189
60
  req.onLoadedInternalHandled = false;
190
61
  req.onInteractiveInternalHandled = false;
@@ -287,12 +158,6 @@ function AjaxRequest() {
287
158
  // ----------------
288
159
  // Instance methods
289
160
  // ----------------
290
- /**
291
- * The process method is called to actually make the request. It builds the
292
- * querystring for GET requests (the content for POST requests), sets the
293
- * appropriate headers if necessary, and calls the
294
- * XMLHttpRequest.send() method
295
- */
296
161
  req.process =
297
162
  function() {
298
163
  if (req.xmlHttpRequest!=null) {
@@ -323,11 +188,6 @@ function AjaxRequest() {
323
188
  req.xmlHttpRequest.send(content);
324
189
  }
325
190
  };
326
-
327
- /**
328
- * An internal function to handle an Object argument, which may contain
329
- * either AjaxRequest field values or parameter name/values
330
- */
331
191
  req.handleArguments =
332
192
  function(args) {
333
193
  for (var i in args) {
@@ -340,11 +200,6 @@ function AjaxRequest() {
340
200
  }
341
201
  }
342
202
  };
343
-
344
- /**
345
- * Returns the results of XMLHttpRequest.getAllResponseHeaders().
346
- * Only available after a response has been returned
347
- */
348
203
  req.getAllResponseHeaders =
349
204
  function() {
350
205
  if (req.xmlHttpRequest!=null) {
@@ -354,12 +209,6 @@ function AjaxRequest() {
354
209
  alert("Cannot getAllResponseHeaders because a response has not yet been received");
355
210
  }
356
211
  };
357
-
358
- /**
359
- * Returns the the value of a response header as returned by
360
- * XMLHttpRequest,getResponseHeader().
361
- * Only available after a response has been returned
362
- */
363
212
  req.getResponseHeader =
364
213
  function(headerName) {
365
214
  if (req.xmlHttpRequest!=null) {
@@ -377,10 +226,6 @@ function AjaxRequest() {
377
226
  // Static methods of the AjaxRequest class
378
227
  // ---------------------------------------
379
228
 
380
- /**
381
- * Returns an XMLHttpRequest object, either as a core object or an ActiveX
382
- * implementation. If an object cannot be instantiated, it will return null;
383
- */
384
229
  AjaxRequest.getXmlHttpRequest = function() {
385
230
  if (window.XMLHttpRequest) {
386
231
  return new XMLHttpRequest();
@@ -405,36 +250,18 @@ AjaxRequest.getXmlHttpRequest = function() {
405
250
  }
406
251
  };
407
252
 
408
- /**
409
- * See if any request is active in the background
410
- */
411
253
  AjaxRequest.isActive = function() {
412
254
  return (AjaxRequest.numActiveAjaxRequests>0);
413
255
  };
414
256
 
415
- /**
416
- * Make a GET request. Pass an object containing parameters and arguments as
417
- * the second argument.
418
- * These areguments may be either AjaxRequest properties to set on the request
419
- * object or name/values to set in the request querystring.
420
- */
421
257
  AjaxRequest.get = function(args) {
422
258
  AjaxRequest.doRequest("GET",args);
423
259
  };
424
260
 
425
- /**
426
- * Make a POST request. Pass an object containing parameters and arguments as
427
- * the second argument.
428
- * These areguments may be either AjaxRequest properties to set on the request
429
- * object or name/values to set in the request querystring.
430
- */
431
261
  AjaxRequest.post = function(args) {
432
262
  AjaxRequest.doRequest("POST",args);
433
263
  };
434
264
 
435
- /**
436
- * The internal method used by the .get() and .post() methods
437
- */
438
265
  AjaxRequest.doRequest = function(method,args) {
439
266
  if (typeof(args)!="undefined" && args!=null) {
440
267
  var myRequest = new AjaxRequest();
@@ -444,13 +271,6 @@ AjaxRequest.doRequest = function(method,args) {
444
271
  }
445
272
  } ;
446
273
 
447
- /**
448
- * Submit a form. The requested URL will be the form's ACTION, and the request
449
- * method will be the form's METHOD.
450
- * Returns true if the submittal was handled successfully, else false so it
451
- * can easily be used with an onSubmit event for a form, and fallback to
452
- * submitting the form normally.
453
- */
454
274
  AjaxRequest.submit = function(theform, args) {
455
275
  var myRequest = new AjaxRequest();
456
276
  if (myRequest==null) { return false; }
@@ -463,13 +283,6 @@ AjaxRequest.submit = function(theform, args) {
463
283
  return true;
464
284
  };
465
285
 
466
- /**
467
- * Serialize a form into a format which can be sent as a GET string or a POST
468
- * content.It correctly ignores disabled fields, maintains order of the fields
469
- * as in the elements[] array. The 'file' input type is not supported, as
470
- * its content is not available to javascript. This method is used internally
471
- * by the submit class method.
472
- */
473
286
  AjaxRequest.serializeForm = function(theform) {
474
287
  var els = theform.elements;
475
288
  var len = els.length;
@@ -515,17 +328,6 @@ AjaxRequest.serializeForm = function(theform) {
515
328
  // Static Class variables
516
329
  // -----------------------
517
330
 
518
- /**
519
- * The number of total AjaxRequest objects currently active and running
520
- */
521
331
  AjaxRequest.numActiveAjaxRequests = 0;
522
-
523
- /**
524
- * An object holding the number of active requests for each group
525
- */
526
332
  AjaxRequest.numActiveAjaxGroupRequests = new Object();
527
-
528
- /**
529
- * The total number of AjaxRequest objects instantiated
530
- */
531
333
  AjaxRequest.numAjaxRequests = 0;
@@ -53,7 +53,8 @@ function UserChatSub(chat_div_id, chat_id, channel, user_id, options={}){
53
53
 
54
54
  App.cable.subscriptions.create({ channel: channel, id: chat_id }, {
55
55
  received: function(data) {
56
- HtmlNode(data, options);
56
+ // HtmlNode(data, options);
57
+ RenderMessage(data);
57
58
  if (data['chat']['sender_id'] != user_id) {
58
59
  TopDot();
59
60
  }
@@ -61,7 +62,23 @@ function UserChatSub(chat_div_id, chat_id, channel, user_id, options={}){
61
62
  })
62
63
  }
63
64
 
64
- function HtmlNode(data, options={}){
65
+ function RenderMessage(data) {
66
+ console.log(data);
67
+ AjaxRequest.post(
68
+ {
69
+ 'url': '<%= Kablam::Engine.routes.url_helpers.message_path %>',
70
+ 'parameters': {'message': JSON.stringify(data['chat'])},
71
+ // 'onSuccess':function(req){ insertAndExecute(target, req.responseText); }
72
+ 'onSuccess': function(req){eval(req.responseText);}
73
+ }
74
+ );
75
+ }
76
+
77
+ function insertHTML(target, content, location) {
78
+
79
+ }
80
+
81
+ function HtmlNode(target, data, options={}){
65
82
  options = {
66
83
  outerDivClass: options.outerDivClass || "pt3 ph3 ph2-l bg-white br2 shadow1 mb3",
67
84
  innerDivClass: options.innerDivClass || "dt w-100 pb2 ph2 mt2",
@@ -88,7 +105,7 @@ function HtmlNode(data, options={}){
88
105
  </div>
89
106
  </div>
90
107
  <div class="${options.messageDivClass}"><p class="${options.messageClass}">${content}</p></div>`;
91
- chatdiv.insertAdjacentElement('afterbegin', new_message);
108
+ target.insertAdjacentElement('afterbegin', new_message);
92
109
  }
93
110
 
94
111
  var scrollPosition;
@@ -1,10 +1,12 @@
1
1
  require 'rest-client'
2
+ require 'json'
2
3
 
3
4
  class KablamController < ApplicationController
4
5
  protect_from_forgery with: :exception
5
6
  before_action :set_model, only: [:create, :update, :undo, :destroy, :form]
6
7
  before_action :set_object, only: [:update, :destroy]
7
8
  before_action :set_undo_object, only: [:undo]
9
+ skip_before_action :verify_authenticity_token, only: [:message]
8
10
  include Concerns::ApiSettings
9
11
 
10
12
  def form
@@ -18,6 +20,16 @@ class KablamController < ApplicationController
18
20
  render layout: false
19
21
  end
20
22
 
23
+ def message
24
+ @message = JSON.parse(params[:message])
25
+ respond_to do |format|
26
+ format.js
27
+ format.html do
28
+ redirect_to request.referrer
29
+ end
30
+ end
31
+ end
32
+
21
33
  def create
22
34
  @object = @model.new(model_params)
23
35
 
@@ -0,0 +1,6 @@
1
+ <div class="alert alert-info note" id="alert-notification" role="alert" onclick="toggle_visibility('displayalert');">
2
+ <div id="displayalert">
3
+ <%= message %>
4
+ </div>
5
+ </div>
6
+
@@ -0,0 +1,3 @@
1
+ <div class="alert alert-info note" role="alert" onclick="toggle_visibility('displayalert')">
2
+ <%= message %><%= link %>
3
+ </div>
@@ -0,0 +1,15 @@
1
+ <div class="pt3 ph3 ph2-l bg-white br2 shadow1 mb3">
2
+ <div class="dt w-100 pb2 ph2 mt2">
3
+ <div class="dtc w2 w3-ns v-mid">
4
+ <img src="<%= message['image'].blank? ? image_path('rocket2.png') : message['image'] %>" class="ba b--black-10 db br-100 w2 w3-ns h2 h3-ns"/>
5
+ </div>
6
+ <div class="dtc v-mid pl3">
7
+ <h1 class="f6 f5-ns fw6 lh-title black mv0"><%= message['username'] %></h1>
8
+ <h2 class="f6 fw4 mt0 mb0 black-60 i"><%= message['created_at'].to_time.strftime("%H:%M:%S%p %m-%d-%Y") %></h2>
9
+ <h2 class="f6 fw4 mt0 mb0 black-60 i">User Time:<%= message['user_time'].to_time.strftime("%H:%M:%S%p %m-%d-%Y") if message['user_time'].present? %></h2>
10
+ </div>
11
+ </div>
12
+ <div class="ph3-l pb2 ">
13
+ <%= simple_format(message['content']) %>
14
+ </div>
15
+ </div>
@@ -1,7 +1,7 @@
1
1
  <%= hide @object %>
2
2
  <% if @object.undoable? %>
3
3
  <%= render_flash message: 'Deleted', partial: 'application/flash_undo',
4
- link: button_to('Undo', kablam_undo_path(@object.class.table_name, @object,
4
+ link: button_to('Undo', undo_path(@object.class.table_name, @object,
5
5
  @object.model_name.singular.to_sym => { destroyed_at: nil }),
6
6
  {data: { disable_with: 'Restoring…' },
7
7
  class: 'no-underline mt3 f4 tc pv2 ph4 white bg-black hover-bg-green shadow-5',
@@ -0,0 +1,5 @@
1
+ var content = '<%= j render "kablam/message", message: @message %>';
2
+ var newMessage = HTMLElement.From(content);
3
+ var target = document.getElementById("kablam-chat-window");
4
+
5
+ target.innerHTML = newMessage.outerHTML + target.innerHTML;
@@ -1,4 +1,5 @@
1
1
  Kablam::Engine.routes.draw do
2
+ post '/message' => 'kablam#message', as: 'message'
2
3
  get '/:name/form' => 'kablam#form', as: 'form'
3
4
  post '/:name' => 'kablam#create', as: 'create'
4
5
  patch '/:name/:id' => 'kablam#update', as: 'update'
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'kablam'
3
- s.version = '0.2.4'
3
+ s.version = '0.2.5'
4
4
  s.date = '2018-09-14'
5
5
  s.summary = "Kablam! All the things you hate. But Faster."
6
6
  s.description = "Gem to make development of everything in rails faster. Form creation & styling, all the resource routes, even actioncable messaging!\n {NOTE: In Development. NOT READY FOR TESTING.}"
@@ -0,0 +1,15 @@
1
+ <div class="pt3 ph3 ph2-l bg-white br2 shadow1 mb3">
2
+ <div class="dt w-100 pb2 ph2 mt2">
3
+ <div class="dtc w2 w3-ns v-mid">
4
+ <img src="<%= message['image'].blank? ? image_path('rocket2.png') : message['image'] %>" class="ba b--black-10 db br-100 w2 w3-ns h2 h3-ns"/>
5
+ </div>
6
+ <div class="dtc v-mid pl3">
7
+ <h1 class="f6 f5-ns fw6 lh-title black mv0"><%= message['username'] %></h1>
8
+ <h2 class="f6 fw4 mt0 mb0 black-60 i"><%= message['created_at'].to_time.strftime("%H:%M:%S%p %m-%d-%Y") %></h2>
9
+ <h2 class="f6 fw4 mt0 mb0 black-60 i">User Time:<%= message['user_time'].to_time.strftime("%H:%M:%S%p %m-%d-%Y") if message['user_time'].present? %></h2>
10
+ </div>
11
+ </div>
12
+ <div class="ph3-l pb2 ">
13
+ <%= simple_format(message['content']) %>
14
+ </div>
15
+ </div>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kablam
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergio Rivas
@@ -67,15 +67,19 @@ files:
67
67
  - app/.DS_Store
68
68
  - app/assets/javascripts/kablam/ajax.js
69
69
  - app/assets/javascripts/kablam/forms.js
70
- - app/assets/javascripts/kablam/messaging.js
70
+ - app/assets/javascripts/kablam/messaging.js.erb
71
71
  - app/assets/stylesheets/kablam.scss
72
72
  - app/channels/chat_channel.rb
73
73
  - app/controllers/concerns/api_settings.rb
74
74
  - app/controllers/kablam_controller.rb
75
75
  - app/views/.DS_Store
76
+ - app/views/application/_flash_notice.html.erb
77
+ - app/views/application/_flash_undo.html.erb
78
+ - app/views/kablam/_message.html.erb
76
79
  - app/views/kablam/create.js.erb
77
80
  - app/views/kablam/destroy.js.erb
78
81
  - app/views/kablam/form.html.erb
82
+ - app/views/kablam/message.js.erb
79
83
  - app/views/kablam/undo.js.erb
80
84
  - app/views/kablam/update.js.erb
81
85
  - app/views/kablam_forms/.DS_Store
@@ -97,6 +101,7 @@ files:
97
101
  - lib/generators/kablam/forms_generator.rb
98
102
  - lib/generators/kablam/install_generator.rb
99
103
  - lib/generators/kablam/messaging_generator.rb
104
+ - lib/generators/kablam/templates/_message.html.erb
100
105
  - lib/generators/kablam/templates/_sample_target_item.html.erb
101
106
  - lib/generators/kablam/templates/chat.rb
102
107
  - lib/generators/kablam/templates/kablam.rb