@@ -3,6 +3,7 @@ import RavenVue from 'raven-js/plugins/vue'
33import Vue from 'vue'
44import VueRouter from 'vue-router'
55import app from './app'
6+ import enquiry from './components/enquiry'
67import grid from './components/grid'
78import con_modal from './components/con-modal'
89import { to_markdown , clean } from './utils'
@@ -12,37 +13,61 @@ Raven.config(dsn, {release: process.env.RELEASE}).addPlugin(RavenVue, Vue).insta
1213
1314Vue . use ( VueRouter )
1415
15- const ConfiguredVueRouter = config => new VueRouter ( {
16- mode : config . router_mode ,
17- routes : [
18- {
19- path : config . url_root ,
20- name : 'index' ,
21- component : grid ,
22- children : [
23- {
24- path : config . url_root + ':link' ,
25- name : 'modal' ,
26- component : con_modal ,
27- }
28- ]
29- } ,
30- ]
31- } )
16+ const ConfiguredVueRouter = config => {
17+ let routes
18+ if ( config . mode === 'grid' ) {
19+ routes = [
20+ {
21+ path : config . url_root ,
22+ name : 'index' ,
23+ component : grid ,
24+ children : [
25+ {
26+ path : config . url_root + ':link' ,
27+ name : 'modal' ,
28+ component : con_modal ,
29+ }
30+ ]
31+ } ,
32+ ]
33+ } else if ( config . mode === 'enquiry' ) {
34+ routes = [
35+ {
36+ path : config . url_root ,
37+ name : 'index' ,
38+ component : enquiry ,
39+ } ,
40+ ]
41+ }
42+ return new VueRouter ( {
43+ mode : config . router_mode ,
44+ routes : routes
45+ } )
46+ }
3247
3348const STRINGS = {
3449 skills_label : 'Skills' ,
3550 contractor_enquiry_message : 'Please enter your details below to enquire about tutoring with {contractor_name}.' ,
51+ enquiry_message : 'Please enter your details below and we will get in touch with you directly.' ,
3652 contractor_enquiry_button : 'Contact {contractor_name}' ,
3753 contractor_details_button : 'Show Profile' ,
3854 submit_enquiry : 'Submit Enquiry' ,
3955 enquiry_submitted_thanks : 'Enquiry submitted, thank you.\n\nYou can now close this window.'
4056}
4157
58+ const MODES = [ 'grid' , 'enquiry' ]
59+
4260module . exports = function ( public_key , config ) {
4361 config = config || { }
4462 let error = null
4563
64+ if ( config . mode === undefined ) {
65+ config . mode = 'grid'
66+ } else if ( ! MODES . includes ( config . mode ) ) {
67+ error = `invalid mode "${ config . mode } ", options are: ${ MODES . join ( ', ' ) } `
68+ config . mode = 'grid'
69+ }
70+
4671 if ( config . api_root === undefined ) {
4772 config . api_root = process . env . SOCKET_API_URL
4873 }
@@ -82,7 +107,7 @@ module.exports = function (public_key, config) {
82107 config : config ,
83108 error : null ,
84109 public_key : public_key ,
85- enquiry_form_info : null ,
110+ enquiry_form_info : { } ,
86111 enquiry_data : { } ,
87112 } ,
88113 components : {
@@ -150,7 +175,7 @@ response text: "${xhr.responseText}"`)
150175 return true
151176 } ,
152177 get_enquiry : function ( ) {
153- if ( this . enquiry_form_info !== null ) {
178+ if ( Object . keys ( this . enquiry_form_info ) . length !== 0 ) {
154179 return
155180 }
156181 let xhr = new window . XMLHttpRequest ( )
@@ -160,22 +185,11 @@ response text: "${xhr.responseText}"`)
160185 if ( xhr . status !== 200 ) {
161186 throw new Error ( `bad response ${ xhr . status } at "${ url } "` )
162187 } else {
163- this . enquiry_form_info = JSON . parse ( xhr . responseText )
188+ this . enquiry_form_info = Object . assign ( { } , this . enquiry_form_info , JSON . parse ( xhr . responseText ) )
164189 }
165190 }
166191 xhr . send ( )
167192 } ,
168- get_text : function ( name , replacements , is_markdown ) {
169- let s = this . config [ name ]
170- for ( let [ k , v ] of Object . entries ( replacements || { } ) ) {
171- s = s . replace ( '{' + k + '}' , v )
172- }
173- if ( is_markdown === true ) {
174- return to_markdown ( s )
175- } else {
176- return s
177- }
178- } ,
179193 submit_enquiry : function ( callback ) {
180194 let data = JSON . stringify ( clean ( this . enquiry_data ) )
181195 let xhr = new window . XMLHttpRequest ( )
@@ -195,6 +209,17 @@ response text: "${xhr.responseText}"`)
195209 }
196210 xhr . send ( data )
197211 } ,
212+ get_text : function ( name , replacements , is_markdown ) {
213+ let s = this . config [ name ]
214+ for ( let [ k , v ] of Object . entries ( replacements || { } ) ) {
215+ s = s . replace ( '{' + k + '}' , v )
216+ }
217+ if ( is_markdown === true ) {
218+ return to_markdown ( s )
219+ } else {
220+ return s
221+ }
222+ } ,
198223 }
199224 } )
200225}
0 commit comments