Velaro_Chat - Version 1.0.0

Version Notes

Initial Release

Download this release

Release Info

Developer Velaro
Extension Velaro_Chat
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

Files changed (2) hide show
  1. js/velaro_chat/velaro-admin.js +108 -0
  2. package.xml +18 -0
js/velaro_chat/velaro-admin.js ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Velaro
3
+ *
4
+ * NOTICE OF LICENSE
5
+ *
6
+ * This source file is subject to the Open Software License (OSL 3.0)
7
+ * that is bundled with this package in the file LICENSE.txt.
8
+ * It is also available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category Velaro
12
+ * @package Velaro_Chat
13
+ * @copyright Copyright (c) 2015 Velaro (http://www.velaro.com)
14
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
15
+ */
16
+
17
+ (function () {
18
+
19
+ document.observe('dom:loaded', function () {
20
+ var setupVelaroSelects = function () {
21
+ var selectMappings = {
22
+ velaro_enabled: 'velaro-enabled',
23
+ velaro_mobile: 'velaro-mobile',
24
+ velaro_visitor_monitoring: 'velaro-visitor-monitoring'
25
+ };
26
+ var keys = Object.keys(selectMappings);
27
+
28
+ keys.each(function (key) {
29
+ //setup initial values
30
+ var value = $$('[name=' + key + ']')[0].value;
31
+ $$('[name=' + selectMappings[key] + '] option').each(function (el) {
32
+ el.writeAttribute('selected', false);
33
+ });
34
+ $$('[name=' + selectMappings[key] + '] option[value="' + value + '"]')[0].writeAttribute('selected', true);
35
+
36
+ //setup change events
37
+ var $select = $$('[name=' + selectMappings[key] + ']')[0];
38
+ $select.stopObserving('change');
39
+ $select.on('change', function (e) {
40
+ var currentValue = $$('[name=' + selectMappings[key] + '] option:selected')[0].value;
41
+ $$('[name=' + key + ']')[0].writeAttribute('value', currentValue);
42
+ });
43
+ });
44
+
45
+ };
46
+ var matchVelaroGroup = function () {
47
+ var pageID = $$('.velaro-page-select option:selected')[0].value;
48
+ var val = $$('[name=velaro_page_assignments]')[0].value;
49
+ var currentAssingments = val ? JSON.parse(val) : {};
50
+ var pageAssignment = currentAssingments['page_' + pageID];
51
+ if (pageAssignment) {
52
+ $$(".velaro-group-select option:selected")[0].writeAttribute("selected", false);
53
+ $$('.velaro-group-select option[value="' + pageAssignment + '"]')[0].writeAttribute("selected", true);
54
+ } else {
55
+ $$(".velaro-group-select option:selected")[0].writeAttribute("selected", false);
56
+ $$('.velaro-group-select option[value="0"]')[0].writeAttribute("selected", true);
57
+ }
58
+ };
59
+ // when the group select changes, set the value that will be saved in our plugins options
60
+ $$('.velaro-group-select')[0].stopObserving('change');
61
+ $$('.velaro-group-select')[0].on('change', function (e) {
62
+ var pageID = $$('.velaro-page-select option:selected')[0].value;
63
+ var val = $$('[name=velaro_page_assignments]')[0].value;
64
+ var currentAssingments = val ? JSON.parse(val) : {};
65
+ currentAssingments['page_' + pageID] = $$('.velaro-group-select option:selected')[0].value;
66
+ $$('[name=velaro_page_assignments]')[0].writeAttribute('value', JSON.stringify(currentAssingments));
67
+ });
68
+ // when the page select changes, set the group select to the correct value
69
+ $$('.velaro-page-select')[0].stopObserving('change');
70
+ $$('.velaro-page-select')[0].on('change', function (e) {
71
+ matchVelaroGroup();
72
+ });
73
+ // on click link, fire request to velaro to get the site identifier/api key for this login, will be stored in our options
74
+ $('velaro_attach').stopObserving('click');
75
+ $('velaro_attach').on('click', function () {
76
+ var userName = $$('[name=velaro_username]')[0].value;
77
+ var password = $$('[name=velaro_password]')[0].value;
78
+ var model = {
79
+ UserName: userName,
80
+ Password: password
81
+ };
82
+ var request = new Ajax.Request('https://app.velaro.com/api/plugins/login',
83
+ {
84
+ method: 'post',
85
+ parameters: JSON.stringify(model),
86
+ contentType: 'application/json',
87
+ dataType: 'json',
88
+ onSuccess: function (response) {
89
+ if(response.status == 200){
90
+ var start = response.responseText.indexOf('<Content>') + 9;
91
+ var end = response.responseText.indexOf('</Content>');
92
+ var data = JSON.parse(response.responseText.substring(start, end));
93
+ $$('[name=velaro_site_identifier]')[0].setValue(data.Identifier);
94
+ $$('[name=velaro_api_key]')[0].setValue(data.ApiKey);
95
+ } else {
96
+ $$('[name=velaro_site_identifier]')[0].setValue('');
97
+ $$('[name=velaro_api_key]')[0].setValue('');
98
+ }
99
+ $$('[name=velaro_submit]')[0].click();
100
+ }
101
+ });
102
+ });
103
+ matchVelaroGroup();
104
+ setupVelaroSelects();
105
+ })
106
+
107
+
108
+ })();
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Velaro_Chat</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="https://opensource.org/licenses/OSL-3.0">Open Software License (OSL)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Add Velaro Live Chat into your pages</summary>
10
+ <description>Add Velaro Live Chat into your pages</description>
11
+ <notes>Initial Release</notes>
12
+ <authors><author><name>Velaro</name><user>jtuttle87</user><email>jonathan@velaro.com</email></author></authors>
13
+ <date>2015-09-24</date>
14
+ <time>15:20:37</time>
15
+ <contents><target name="magedesign"><dir name="."><dir name="app"><dir name="design"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="velaro.xml" hash=""/></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="velaro.xml" hash=""/></dir></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="."><dir name="app"><dir name="etc"><dir name="modules"><file name="Velaro_Chat.xml" hash=""/></dir></dir></dir></dir></target><target name="mageweb"><dir name="."><dir name="js"><dir name="velaro_chat"><file name="velaro-admin.js" hash="f9144c22f6ccf99022c85bc698796099"/></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.3.0</min><max>5.5.0</max></php></required></dependencies>
18
+ </package>