whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ru...@apache.org
Subject [whimsy] branch master updated: rough in an email form
Date Mon, 08 Apr 2019 01:37:35 GMT
This is an automated email from the ASF dual-hosted git repository.

rubys pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git


The following commit(s) were added to refs/heads/master by this push:
     new 026e7b7  rough in an email form
026e7b7 is described below

commit 026e7b70e0cc22f541fbe3ca8858f47bb517f273
Author: Sam Ruby <rubys@intertwingly.net>
AuthorDate: Sun Apr 7 21:37:18 2019 -0400

    rough in an email form
---
 www/board/agenda/public/stylesheets/app.css  | 12 +++++
 www/board/agenda/views/actions/email.json.rb | 28 +++++++++++
 www/board/agenda/views/buttons/email.js.rb   | 72 ++++++++++++++++++++++++++--
 www/board/agenda/views/utils.js.rb           |  6 ++-
 4 files changed, 113 insertions(+), 5 deletions(-)

diff --git a/www/board/agenda/public/stylesheets/app.css b/www/board/agenda/public/stylesheets/app.css
index aa1e1a7..06793f5 100644
--- a/www/board/agenda/public/stylesheets/app.css
+++ b/www/board/agenda/public/stylesheets/app.css
@@ -548,3 +548,15 @@ input[type=file]#upload {
   font-family: monospace;
   overflow: hidden;
 }
+
+#email-form input {
+  display: inline;
+  width: 80%;
+  padding-right: 5px;
+  padding-left: 5px;
+}
+
+.reminder .modal-content button {
+  margin-left: 0.5em;
+  margin-bottom: 0em;
+}
diff --git a/www/board/agenda/views/actions/email.json.rb b/www/board/agenda/views/actions/email.json.rb
new file mode 100644
index 0000000..5d208b5
--- /dev/null
+++ b/www/board/agenda/views/actions/email.json.rb
@@ -0,0 +1,28 @@
+#
+# send email
+#
+
+ASF::Mail.configure
+
+# extract values for each field
+to, cc, subject, body = @to, @cc, @subject, @body
+
+# construct from address
+sender = ASF::Person.find(env.user)
+from = "#{sender.public_name.inspect} <#{sender.id}@apache.org>".untaint
+
+# construct email
+mail = Mail.new do
+  from from
+  to to
+  cc cc if cc and not cc.empty?
+  subject subject
+
+  body body
+end
+
+# deliver mail
+mail.deliver!
+
+# return email in the response
+{mail: mail.to_s}
diff --git a/www/board/agenda/views/buttons/email.js.rb b/www/board/agenda/views/buttons/email.js.rb
index 3ae3a7b..1c6dbc8 100644
--- a/www/board/agenda/views/buttons/email.js.rb
+++ b/www/board/agenda/views/buttons/email.js.rb
@@ -3,9 +3,15 @@
 #
 
 class Email < Vue
+  def initialize
+    @email = {}
+  end
+
   def render
     _button.btn 'send email', class: self.mailto_class(),
       onClick: self.launch_email_client
+
+    _EmailForm email: @email
   end
 
   # render 'send email' as a primary button if the viewer is the shepherd for
@@ -31,7 +37,7 @@ class Email < Vue
   end
 
   # launch email client, pre-filling the destination, subject, and body
-  def launch_email_client()
+  def launch_email_client(event)
     mail_list = @@item.mail_list
     mail_list = "private@#{mail_list}.apache.org" unless mail_list.include? '@'
 
@@ -77,8 +83,66 @@ class Email < Vue
       end
     end
 
-    window.location = "mailto:#{to}?cc=#{cc}" +
-      "&subject=#{encodeURIComponent(subject)}" +
-      "&body=#{encodeURIComponent(body)}"
+    if event.ctrlKey or event.shiftKey or event.metaKey
+      @email = {
+        to: to,
+        cc: cc,
+        subject: subject,
+        body: body
+      }
+
+      jQuery('#email-form').modal(:show)
+    else
+      window.location = "mailto:#{to}?cc=#{cc}" +
+        "&subject=#{encodeURIComponent(subject)}" +
+        "&body=#{encodeURIComponent(body)}"
+    end
+  end
+end
+
+class EmailForm < Vue
+  def render
+    _ModalDialog.email_form! color: 'commented' do
+      _h4 "Send email - #{@@email.subject}"
+
+      # input field: to
+      _div.form_group.row do
+        _label.col_sm_2 'To', for: 'email-to'
+        _input.col_sm_10.email_to! placeholder: "destination email address",
+          disabled: @disabled, value: @@email.to
+      end
+
+      # input field: cc
+      _div.form_group.row do
+        _label.col_sm_2 'CC', for: 'email-cc'
+        _input.col_sm_10.email_cc! placeholder: "cc list", disabled: @disabled,
+          value: @@email.cc
+      end
+
+      # input field: subject
+      _div.form_group.row do
+        _label.col_sm_2 'Subject', for: 'email-subject'
+        _input.col_sm_10.email_subject! placeholder: "email subject",
+        disabled: @disabled, value: @@email.subject
+      end
+
+      # input field: body
+      _textarea.email_body! label: 'Body', placeholder: "email text",
+        disabled: @disabled, value: @@email.body, rows: 10
+
+      _button.btn_default 'Cancel', type: 'button', data_dismiss: 'modal'
+      _button.btn_primary 'Send', type: 'button', onClick: self.send,
+        disabled: @disabled
+    end
+  end
+
+  def send(event)
+    @disabled = true
+    post 'email', @@email do |response|
+      console.log response
+      @disabled = false
+      jQuery('#email-form').modal(:hide)
+      document.body.classList.remove('modal-open')
+    end
   end
 end
diff --git a/www/board/agenda/views/utils.js.rb b/www/board/agenda/views/utils.js.rb
index 7bead82..0e5f503 100644
--- a/www/board/agenda/views/utils.js.rb
+++ b/www/board/agenda/views/utils.js.rb
@@ -57,7 +57,11 @@ def post(target, data, &block)
           elsif xhr.response.exception
             message = "Exception\n#{xhr.response.exception}"
           else
-            message = "Exception\n#{JSON.parse(xhr.responseText).exception}"
+            begin
+              message = "Exception\n#{JSON.parse(xhr.responseText).exception}"
+            rescue
+              message = "Exception\n#{xhr.responseText}"
+            end
           end
 
           console.log(message)


Mime
View raw message