From 16092ba81642dfa747de19f175a3e932d3b5f657 Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Sat, 31 Jan 2015 04:50:05 +0000 Subject: [PATCH] VRFS-2697 website validator initial commit --- .../javascripts/website_validator.js.coffee | 16 ++++++++++++++++ .../client/website_validator.css.scss | 2 ++ web/app/controllers/spikes_controller.rb | 5 +++++ .../views/clients/_website_validator.html.slim | 2 ++ web/app/views/spikes/site_validate.html.slim | 13 +++++++++++++ web/config/routes.rb | 1 + 6 files changed, 39 insertions(+) create mode 100644 web/app/assets/javascripts/website_validator.js.coffee create mode 100644 web/app/assets/stylesheets/client/website_validator.css.scss create mode 100644 web/app/views/clients/_website_validator.html.slim create mode 100644 web/app/views/spikes/site_validate.html.slim diff --git a/web/app/assets/javascripts/website_validator.js.coffee b/web/app/assets/javascripts/website_validator.js.coffee new file mode 100644 index 000000000..578ccb133 --- /dev/null +++ b/web/app/assets/javascripts/website_validator.js.coffee @@ -0,0 +1,16 @@ +$ = jQuery +context = window +context.JK ||= {}; + +context.JK.WebsiteValidator = class WebsiteValidator + constructor: (@app, input_id) -> + @EVENTS = context.JK.EVENTS + @rest = context.JK.Rest() + @url_input = $(input_id) + + init: () => + # @root = $($('#template-download-jamtrack').html()) + + validate: () => + regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/ + regexp.test(@url_input.value) diff --git a/web/app/assets/stylesheets/client/website_validator.css.scss b/web/app/assets/stylesheets/client/website_validator.css.scss new file mode 100644 index 000000000..1d6c5eb35 --- /dev/null +++ b/web/app/assets/stylesheets/client/website_validator.css.scss @@ -0,0 +1,2 @@ +@import "client/common"; + diff --git a/web/app/controllers/spikes_controller.rb b/web/app/controllers/spikes_controller.rb index b07987b4d..1c3c39e6e 100644 --- a/web/app/controllers/spikes_controller.rb +++ b/web/app/controllers/spikes_controller.rb @@ -37,4 +37,9 @@ class SpikesController < ApplicationController Notification.send_subscription_message('test', '2', '{"msg": "oh hai 2"}') render text: 'oh hai' end + + def site_validate + render :layout => 'web' + end + end diff --git a/web/app/views/clients/_website_validator.html.slim b/web/app/views/clients/_website_validator.html.slim new file mode 100644 index 000000000..38703f37b --- /dev/null +++ b/web/app/views/clients/_website_validator.html.slim @@ -0,0 +1,2 @@ +input type='text' id="website_#{siteid}" + diff --git a/web/app/views/spikes/site_validate.html.slim b/web/app/views/spikes/site_validate.html.slim new file mode 100644 index 000000000..2b6b1e86c --- /dev/null +++ b/web/app/views/spikes/site_validate.html.slim @@ -0,0 +1,13 @@ += javascript_include_tag "website_validator" += render "clients/website_validator", siteid: 'foobar' += stylesheet_link_tag "client/website_validator" + +javascript: + var initialized = false; + $(document).on('JAMKAZAM_READY', function(e, data) { + setTimeout(function() { + window.website_validator = new JK.WebsiteValidator(data.app, "website_foobar") + website_validator.init() + $('#website_foobar').val('http://www.jamkazam.com') + }, 1) + }) diff --git a/web/config/routes.rb b/web/config/routes.rb index 2a18c7fce..50d0ae687 100644 --- a/web/config/routes.rb +++ b/web/config/routes.rb @@ -92,6 +92,7 @@ SampleApp::Application.routes.draw do match '/launch_app', to: 'spikes#launch_app' match '/websocket', to: 'spikes#websocket' match '/test_subscription', to: 'spikes#subscription' + match '/site_validate', to: 'spikes#site_validate' # junk pages match '/help', to: 'static_pages#help'