Conlabz_CrConnect - Version 3.1.8

Version Notes

Bugfix: Can't get groups and forms from CleverReach

Download this release

Release Info

Developer Conlabz GmbH
Extension Conlabz_CrConnect
Version 3.1.8
Comparing to
See all releases


Code changes from version 3.1.7 to 3.1.8

app/code/community/Conlabz/CrConnect/Model/Api.php CHANGED
@@ -585,7 +585,7 @@ class Conlabz_CrConnect_Model_Api extends Mage_Core_Model_Abstract
585
  $groupDetails = $this->_client->groupGetDetails($this->_apiKey, $listId);
586
 
587
  if ($groupDetails->status !== self::SUCCESS_STATUS) {
588
- $this->_helper->log("CleverReach Connection Error: " . $groupDetails);
589
  return $groupDetails;
590
  }
591
 
585
  $groupDetails = $this->_client->groupGetDetails($this->_apiKey, $listId);
586
 
587
  if ($groupDetails->status !== self::SUCCESS_STATUS) {
588
+ $this->_helper->log("CleverReach Connection Error: " . $groupDetails->message);
589
  return $groupDetails;
590
  }
591
 
app/code/community/Conlabz/CrConnect/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Conlabz_CrConnect>
5
- <version>3.1.7</version>
6
  </Conlabz_CrConnect>
7
  </modules>
8
  <global>
2
  <config>
3
  <modules>
4
  <Conlabz_CrConnect>
5
+ <version>3.1.8</version>
6
  </Conlabz_CrConnect>
7
  </modules>
8
  <global>
package.xml CHANGED
@@ -1,18 +1,18 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Conlabz_CrConnect</name>
4
- <version>3.1.7</version>
5
  <stability>stable</stability>
6
  <license>GNU General Public License</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Synchronizes your Magento subscribers, customers and sales with CleverReach Email Marketing Software.</summary>
10
  <description>With CleverReach (http://www.cleverreach.de) you can create professional emails online, dispatch them reliably, track their success and manage receivers. &#xFEFF;&#xFEFF;&#xFEFF;CleverReach&#xFEFF;&#xFEFF;&#xFEFF; is equipped with a particularly user-friendly interface, which you can use intuitively and without special knowledge.</description>
11
- <notes>Bugfix: Rename param due to duplicate name</notes>
12
  <authors><author><name>conlabz GmbH</name><user>conlabz</user><email>info@conlabz.de</email></author></authors>
13
- <date>2016-04-11</date>
14
- <time>14:38:24</time>
15
- <contents><target name="magecommunity"><dir name="Conlabz"><dir name="CrConnect"><dir name="Block"><dir name="Adminhtml"><dir name="Customer"><dir name="Edit"><dir name="Tab"><file name="Newsletter.php" hash="ff47d3028a8e766077ee78affd52eea6"/></dir></dir></dir><dir name="Newsletter"><file name="Subscriber.php" hash="e1b516bc593a41bcc6d00b259776c8b8"/></dir></dir><dir name="Config"><file name="GroupsApis.php" hash="da3907dba74081f724f23b7a6b6df255"/><file name="Key.php" hash="44c2fc49a5b97cdacec1cada7a256a88"/><file name="Url.php" hash="becf4140ce0997e95548b758d8b7ed68"/></dir><dir name="Customer"><file name="Newsletter.php" hash="1acc2f35d1c67e8e15640c3117a00dfd"/></dir><file name="Groupsapis.php" hash="f20a158b439469cdd498b16cc459ab4a"/></dir><dir name="Helper"><file name="Data.php" hash="9e9584f6771982ee8eba5a59155d02dd"/></dir><dir name="Model"><file name="Api.php" hash="c1085f6baf13328cbe78034b65f481fc"/><dir name="Checkout"><file name="Observer.php" hash="8fd916c7332ce6ebfa9197666c2987a9"/></dir><dir name="Customer"><file name="Observer.php" hash="878370bd5958b3813f0b90f395b27ecf"/></dir><dir name="Newsletter"><file name="Subscriber.php" hash="96e4b452bf916d5afa209cb80192eba0"/></dir><file name="Observer.php" hash="92c2338e8e4223deefaa494f46955013"/><file name="Search.php" hash="5419d8b49f901e2d28eff3d57ae9de4f"/><file name="Subscriber.php" hash="3e3698a40f540a038ad4dc56e1975070"/><dir name="System"><dir name="Config"><dir name="Source"><file name="EmptyForms.php" hash="910b9588b11edf73be1fc0103e49b997"/><file name="EmptyList.php" hash="6fe676d12ff5fa9231c3b0869b1ec750"/></dir></dir></dir><dir name="Website"><file name="Observer.php" hash="6c068fc61ae6ed512cbdce2a28f48cb7"/></dir></dir><dir name="Test"><dir name="Config"><file name="ActivationXml.php" hash="0270720ffc36ea493b9c976377bdfdcd"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="CrconfigController.php" hash="fdb46a1200e564d69426aba8a518e487"/><file name="CrconnectController.php" hash="fa3cb1d4f515cabd0e378715258db203"/></dir><file name="HookController.php" hash="2c81dd3ebd9310ca86afc732b2e2d1c6"/><file name="ManageController.php" hash="12ff08a154cb21dc0fe4fed3cd718d1c"/><file name="SearchController.php" hash="0141ec8a414c86619ff63c6a856af470"/><file name="SubscriberController.php" hash="3bbf81a698e630d4a04f638a53ecd3e9"/><file name="UnsubscribeController.php" hash="eaba3ee3bef995d4bb6f7e17b1709585"/></dir><dir name="etc"><file name="adminhtml.xml" hash="05f8a5b43c8abe877f05e09eec5d8c65"/><file name="config.xml" hash="824dd5c0fe7039f9a19cadcbc130f34c"/><file name="jstranslator.xml" hash="040e5e790dcae18ddf223d54e38e45b0"/><file name="system.xml" hash="634952e319523e7640152ddaeedeaef9"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Conlabz_CrConnect.xml" hash="dd6482e7f0daedb3387e80bdff66f321"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="crconnect.xml" hash="dd115195559fe2058fbd6fbdceabdddc"/></dir><dir name="template"><dir name="crconnect"><dir name="customer"><dir name="account"><dir name="dashboard"><file name="info.phtml" hash="a533451e27b90284d3414e391b460231"/></dir></dir><dir name="form"><file name="newsletter.phtml" hash="4a1309d0d6d2587c8534dd4a1ccdf235"/></dir></dir></dir></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="crconnect.xml" hash="fac2e1194c8c007a54abfe3e82fd6834"/></dir><dir name="template"><dir name="crconnect"><file name="config.phtml" hash="9f2232c8311fa439434d8023181a7ab5"/><dir name="newsletter"><dir name="subscriber"><file name="list.phtml" hash="2d7dd105e2c543d19746ada03fa54ff8"/></dir></dir><dir name="system"><dir name="config"><dir name="form"><dir name="field"><file name="array_groups.phtml" hash="ac84db9b1e8b342337a478ecba62e0b1"/><file name="cr_array_groups.phtml" hash="c924ef81c5699817327580eb7b8a2e86"/></dir></dir></dir></dir></dir></dir></dir></dir></dir></target><target name="magelocale"><dir name="de_DE"><file name="Conlabz_CleverReach.csv" hash="4cb844c7288d9995d21d39eb4015fa44"/></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="base"><dir name="default"><dir name="images"><dir name="cleverreach"><file name="cleverreach-logo.png" hash="bff60f831ca9e1dc9bcbdb2e3f5a5805"/></dir></dir><dir name="js"><file name="crconnect.js" hash="72c951b0b46862253c7159255d82b2e0"/></dir></dir></dir></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Conlabz_CrConnect</name>
4
+ <version>3.1.8</version>
5
  <stability>stable</stability>
6
  <license>GNU General Public License</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Synchronizes your Magento subscribers, customers and sales with CleverReach Email Marketing Software.</summary>
10
  <description>With CleverReach (http://www.cleverreach.de) you can create professional emails online, dispatch them reliably, track their success and manage receivers. &#xFEFF;&#xFEFF;&#xFEFF;CleverReach&#xFEFF;&#xFEFF;&#xFEFF; is equipped with a particularly user-friendly interface, which you can use intuitively and without special knowledge.</description>
11
+ <notes>Bugfix: Can't get groups and forms from CleverReach</notes>
12
  <authors><author><name>conlabz GmbH</name><user>conlabz</user><email>info@conlabz.de</email></author></authors>
13
+ <date>2016-04-14</date>
14
+ <time>08:21:36</time>
15
+ <contents><target name="magecommunity"><dir name="Conlabz"><dir name="CrConnect"><dir name="Block"><dir name="Adminhtml"><dir name="Customer"><dir name="Edit"><dir name="Tab"><file name="Newsletter.php" hash="ff47d3028a8e766077ee78affd52eea6"/></dir></dir></dir><dir name="Newsletter"><file name="Subscriber.php" hash="e1b516bc593a41bcc6d00b259776c8b8"/></dir></dir><dir name="Config"><file name="GroupsApis.php" hash="da3907dba74081f724f23b7a6b6df255"/><file name="Key.php" hash="44c2fc49a5b97cdacec1cada7a256a88"/><file name="Url.php" hash="becf4140ce0997e95548b758d8b7ed68"/></dir><dir name="Customer"><file name="Newsletter.php" hash="1acc2f35d1c67e8e15640c3117a00dfd"/></dir><file name="Groupsapis.php" hash="f20a158b439469cdd498b16cc459ab4a"/></dir><dir name="Helper"><file name="Data.php" hash="9e9584f6771982ee8eba5a59155d02dd"/></dir><dir name="Model"><file name="Api.php" hash="061fec482fcef35acecb4e956c2e3586"/><dir name="Checkout"><file name="Observer.php" hash="8fd916c7332ce6ebfa9197666c2987a9"/></dir><dir name="Customer"><file name="Observer.php" hash="878370bd5958b3813f0b90f395b27ecf"/></dir><dir name="Newsletter"><file name="Subscriber.php" hash="96e4b452bf916d5afa209cb80192eba0"/></dir><file name="Observer.php" hash="92c2338e8e4223deefaa494f46955013"/><file name="Search.php" hash="5419d8b49f901e2d28eff3d57ae9de4f"/><file name="Subscriber.php" hash="3e3698a40f540a038ad4dc56e1975070"/><dir name="System"><dir name="Config"><dir name="Source"><file name="EmptyForms.php" hash="910b9588b11edf73be1fc0103e49b997"/><file name="EmptyList.php" hash="6fe676d12ff5fa9231c3b0869b1ec750"/></dir></dir></dir><dir name="Website"><file name="Observer.php" hash="6c068fc61ae6ed512cbdce2a28f48cb7"/></dir></dir><dir name="Test"><dir name="Config"><file name="ActivationXml.php" hash="0270720ffc36ea493b9c976377bdfdcd"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="CrconfigController.php" hash="fdb46a1200e564d69426aba8a518e487"/><file name="CrconnectController.php" hash="fa3cb1d4f515cabd0e378715258db203"/></dir><file name="HookController.php" hash="2c81dd3ebd9310ca86afc732b2e2d1c6"/><file name="ManageController.php" hash="12ff08a154cb21dc0fe4fed3cd718d1c"/><file name="SearchController.php" hash="0141ec8a414c86619ff63c6a856af470"/><file name="SubscriberController.php" hash="3bbf81a698e630d4a04f638a53ecd3e9"/><file name="UnsubscribeController.php" hash="eaba3ee3bef995d4bb6f7e17b1709585"/></dir><dir name="etc"><file name="adminhtml.xml" hash="05f8a5b43c8abe877f05e09eec5d8c65"/><file name="config.xml" hash="1da26aec72dec7d8ef1af2526aff552e"/><file name="jstranslator.xml" hash="040e5e790dcae18ddf223d54e38e45b0"/><file name="system.xml" hash="634952e319523e7640152ddaeedeaef9"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Conlabz_CrConnect.xml" hash="dd6482e7f0daedb3387e80bdff66f321"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="crconnect.xml" hash="dd115195559fe2058fbd6fbdceabdddc"/></dir><dir name="template"><dir name="crconnect"><dir name="customer"><dir name="account"><dir name="dashboard"><file name="info.phtml" hash="a533451e27b90284d3414e391b460231"/></dir></dir><dir name="form"><file name="newsletter.phtml" hash="4a1309d0d6d2587c8534dd4a1ccdf235"/></dir></dir></dir></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="crconnect.xml" hash="fac2e1194c8c007a54abfe3e82fd6834"/></dir><dir name="template"><dir name="crconnect"><file name="config.phtml" hash="9f2232c8311fa439434d8023181a7ab5"/><dir name="newsletter"><dir name="subscriber"><file name="list.phtml" hash="2d7dd105e2c543d19746ada03fa54ff8"/></dir></dir><dir name="system"><dir name="config"><dir name="form"><dir name="field"><file name="array_groups.phtml" hash="ac84db9b1e8b342337a478ecba62e0b1"/><file name="cr_array_groups.phtml" hash="c924ef81c5699817327580eb7b8a2e86"/></dir></dir></dir></dir></dir></dir></dir></dir></dir></target><target name="magelocale"><dir name="de_DE"><file name="Conlabz_CleverReach.csv" hash="4cb844c7288d9995d21d39eb4015fa44"/></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="images"><dir name="cleverreach"><file name="cleverreach-logo.png" hash="bff60f831ca9e1dc9bcbdb2e3f5a5805"/></dir></dir><dir name="js"><file name="crconnect.js" hash="ae1bca0667c52897d9f203b3bc3dd56e"/></dir></dir></dir></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>
skin/adminhtml/base/default/js/crconnect.js DELETED
@@ -1,221 +0,0 @@
1
- Crconnect = Class.create();
2
- Crconnect.prototype = {
3
- initialize: function() {
4
-
5
-
6
- },
7
- confirmMainKey: function(manual) {
8
-
9
- var key = $("crroot_crconnect_api_key").value;
10
-
11
- if (manual){
12
- $$(".simple-added-row").each(function(el){
13
- callRowDelete(el.id);
14
- savedDefaultListId = false;
15
- savedDefaultFormId = false;
16
- });
17
- }
18
-
19
- if (key){
20
- var url = baseConfirmKeyUrl + 'key/' + key;
21
- new Ajax.Request(url, {
22
- method: 'post',
23
- onSuccess: function(transport) {
24
-
25
- var select = $('crroot_crconnect_list_id');
26
- Crconnect.cleanSelect('crroot_crconnect_list_id');
27
-
28
- // If no results come, revert all group and form selects to default states
29
- if (transport.responseText == "empty"){
30
- Crconnect.resetGroupList();
31
- Crconnect.resetFormList();
32
- // Reload block with keys
33
- Crconnect.reloadKeysBlock();
34
- Crconnect.confirmDisable();
35
- return false;
36
- }
37
-
38
- // Fill Main groups select with groups list
39
- var editData = transport.responseText.evalJSON(true);
40
- Crconnect.reloadKeysBlock(editData);
41
- select.insert(new Element('option', {value: ''}).update(crconnectLang['please:select:group']));
42
- for (var i = 0; i < editData.length; i++){
43
- select.insert(new Element('option', {value: editData[i].id}).update(editData[i].name));
44
- }
45
-
46
- if (savedDefaultListId){
47
- select.value = savedDefaultListId;
48
- savedDefaultListId = false;
49
- }
50
- Crconnect.changeGroupId();
51
-
52
-
53
- }
54
- });
55
- }else{
56
- Crconnect.resetGroupList();
57
- }
58
- Crconnect.confirmDisable();
59
-
60
- },
61
- reloadKeysBlock: function(editData){
62
-
63
- var select = '<select class="crconnect-groups-select" onchange="Crconnect.changeSubGroup(this)" id="#{_id}_crconnect" name="groups[crconnect][fields][groups_keys][value][#{_id}][crconnect]">';
64
- select += '<option value="">'+crconnectLang['please:select:group']+'</option>';
65
- if (editData){
66
- for (var i = 0; i < editData.length; i++){
67
- select += '<option value="'+editData[i].id+'">'+editData[i].name+'</option>';
68
- }
69
- }
70
- stringElements['crconnect'] = select + '</select>';
71
- initRowTemplate();
72
-
73
- },
74
- changeGroupId: function(){
75
-
76
- var groupId = $("crroot_crconnect_list_id").value;
77
- var key = $("crroot_crconnect_api_key").value;
78
-
79
- if (key && groupId){
80
- var url = baseChangeGroupUrl + 'group/' + groupId + '/key/' + key;
81
- new Ajax.Request(url, {
82
- method: 'post',
83
- onSuccess: function(transport) {
84
-
85
- var select = $('crroot_crconnect_form_id');
86
-
87
- Crconnect.cleanSelect('crroot_crconnect_form_id');
88
- if (transport.responseText == "empty"){
89
- Crconnect.resetFormList();
90
- return false;
91
- }
92
- var editData = transport.responseText.evalJSON(true);
93
- select.insert(new Element('option', {value: ''}).update(crconnectLang['please:select:form']));
94
- for (var i = 0; i < editData.length; i++){
95
- select.insert(new Element('option', {value: editData[i].id}).update(editData[i].name));
96
- }
97
-
98
- if (savedDefaultFormId){
99
- select.value = savedDefaultFormId;
100
- savedDefaultFormId = false;
101
- }
102
-
103
- }
104
- });
105
- }else{
106
- Crconnect.resetFormList();
107
- }
108
- },
109
- changeSubGroup: function(element){
110
-
111
- var selectedValue = element.value;
112
- var id = element.id;
113
- id = id.replace("_crconnect", "");
114
-
115
- var key = $("crroot_crconnect_api_key").value;
116
- var url = baseChangeGroupUrl + 'group/' + selectedValue + '/key/' + key;
117
-
118
- new Ajax.Request(url, {
119
- method: 'post',
120
- onSuccess: function(transport) {
121
-
122
- var select = $(id+'_formid');
123
-
124
- Crconnect.cleanSelect(id+'_formid');
125
- if (transport.responseText == "empty"){
126
- Crconnect.resetFormList(id+'_formid');
127
- return false;
128
- }
129
- var editData = transport.responseText.evalJSON(true);
130
- select.insert(new Element('option', {value: ''}).update(crconnectLang['please:select:form']));
131
- for (var i = 0; i < editData.length; i++){
132
- select.insert(new Element('option', {value: editData[i].id}).update(editData[i].name));
133
- }
134
-
135
- if (savedFormsKeys){
136
-
137
- if (savedFormsKeys[id]){
138
- select.value = savedFormsKeys[id];
139
- }
140
-
141
- }
142
- // if (savedDefaultFormId){
143
- // select.value = savedDefaultFormId;
144
- // savedDefaultFormId = false;
145
- // }
146
-
147
- }
148
- });
149
-
150
- // console.log(id);
151
-
152
-
153
- },
154
- confirmEnable: function(){
155
-
156
- $("confirm-key-button").removeClassName('disabled');
157
- $("confirm-key-button").disabled = false;
158
-
159
- },
160
- confirmDisable: function(){
161
-
162
- $("confirm-key-button").addClassName('disabled');
163
- $("confirm-key-button").disabled = true;
164
-
165
- },
166
- resetFormList: function(formId){
167
-
168
- if (!formId){
169
- formId = 'crroot_crconnect_form_id';
170
- }
171
- Crconnect.cleanSelect(formId);
172
- $(formId).insert(new Element('option', {value: ''}).update(crconnectLang['please:select:form:default']));
173
-
174
- },
175
- resetGroupList: function(formId){
176
-
177
- if (!formId){
178
- formId = 'crroot_crconnect_list_id';
179
- }
180
-
181
- Crconnect.cleanSelect(formId);
182
- $(formId).insert(new Element('option', {value: ''}).update(crconnectLang['please:select:group:default']));
183
-
184
- },
185
- cleanSelect: function (selectId){
186
-
187
- var options = $$('select#'+selectId+' option');
188
- var select = $(selectId);
189
- for (var i = 0; i < options.length; i++) {
190
- options[i].remove();
191
- }
192
-
193
- },
194
- fillSelectedGroups: function(){
195
-
196
- if (typeof editedSelects != "undefined"){
197
- if (editedSelects.length > 0){
198
- for (var i = 0; i < editedSelects.length; i++){
199
- Crconnect.changeSubGroup($(editedSelects[i]+"_crconnect"));
200
- }
201
- }
202
- }
203
-
204
- }
205
-
206
- }
207
- Crconnect = new Crconnect();
208
-
209
- function initCleverReach(){
210
-
211
- try{
212
- Crconnect.confirmMainKey();
213
- Event.observe('crroot_crconnect_list_id', 'change', Crconnect.changeGroupId);
214
- Event.observe('crroot_crconnect_api_key', 'keyup', Crconnect.confirmEnable);
215
- Crconnect.fillSelectedGroups();
216
- }catch(e){
217
-
218
- }
219
-
220
- }
221
- Event.observe(window, 'load', initCleverReach);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
skin/adminhtml/{base → default}/default/images/cleverreach/cleverreach-logo.png RENAMED
File without changes
skin/adminhtml/default/default/js/crconnect.js ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Crconnect = Class.create();
2
+ Crconnect.prototype = {
3
+ initialize: function (options, elements) {
4
+ this.options = options;
5
+ this.elements = elements;
6
+ },
7
+ confirmMainKey: function (manual)
8
+ {
9
+ var key = $("crroot_crconnect_api_key").value,
10
+ self = this;
11
+ if (manual) {
12
+ $$(".simple-added-row").each(function (el) {
13
+ callRowDelete(el.id);
14
+ self.options.savedDefaultListId = false;
15
+ self.options.savedDefaultFormId = false;
16
+ });
17
+ }
18
+
19
+ if (key) {
20
+ var url = this.options.baseConfirmKeyUrl + 'crconnectkey/' + key;
21
+ new Ajax.Request(url, {
22
+ method: 'get',
23
+ onSuccess: function (transport) {
24
+ var select = $('crroot_crconnect_list_id');
25
+ self.cleanSelect('crroot_crconnect_list_id');
26
+ // If no results come, revert all group and form selects to default states
27
+ if (transport.responseText == "empty") {
28
+ self.resetGroupList();
29
+ self.resetFormList();
30
+ self.reloadKeysBlock();
31
+ self.confirmDisable();
32
+ return false;
33
+ }
34
+ // Fill Main groups select with groups list
35
+ var editData = transport.responseText.evalJSON(true);
36
+ self.reloadKeysBlock(editData);
37
+ select.insert(new Element('option', {
38
+ value: ''
39
+ }).update(Translator.translate('Please select subscribers group')));
40
+ for (var i = 0; i < editData.length; i++) {
41
+ select.insert(new Element('option', {
42
+ value: editData[i].id
43
+ }).update(editData[i].name));
44
+ }
45
+
46
+ if (self.options.savedDefaultListId) {
47
+ select.value = self.options.savedDefaultListId;
48
+ self.options.savedDefaultListId = false;
49
+ }
50
+ self.changeGroupId();
51
+ }
52
+ });
53
+ } else {
54
+ this.resetGroupList();
55
+ }
56
+ this.confirmDisable();
57
+ },
58
+ reloadKeysBlock: function (editData)
59
+ {
60
+ var select = '<select class="crconnect-groups-select" onchange="Crconnect.changeSubGroup(this)" id="#{_id}_crconnect" name="groups[crconnect][fields][groups_keys][value][#{_id}][crconnect]">';
61
+ select += '<option value="">' + Translator.translate('Please select subscribers group') + '</option>';
62
+ if (editData) {
63
+ for (var i = 0; i < editData.length; i++) {
64
+ select += '<option value="' + editData[i].id + '">' + editData[i].name + '</option>';
65
+ }
66
+ }
67
+ this.elements.stringElements['crconnect'] = select + '</select>';
68
+ initRowTemplate();
69
+ },
70
+ changeGroupId: function ()
71
+ {
72
+ var groupId = $("crroot_crconnect_list_id").value;
73
+ var key = $("crroot_crconnect_api_key").value;
74
+ var self = this;
75
+ if (key && groupId) {
76
+ var url = self.options.baseChangeGroupUrl + 'group/' + groupId + '/crconnectkey/' + key;
77
+ new Ajax.Request(url, {
78
+ method: 'get',
79
+ onSuccess: function (transport) {
80
+ var select = $('crroot_crconnect_form_id');
81
+ self.cleanSelect('crroot_crconnect_form_id');
82
+ if (transport.responseText == "empty") {
83
+ self.resetFormList();
84
+ return false;
85
+ }
86
+ var editData = transport.responseText.evalJSON(true);
87
+ select.insert(new Element('option', {
88
+ value: ''
89
+ }).update(Translator.translate('Please select form')));
90
+ for (var i = 0; i < editData.length; i++) {
91
+ select.insert(new Element('option', {
92
+ value: editData[i].id
93
+ }).update(editData[i].name));
94
+ }
95
+
96
+ if (self.options.savedDefaultFormId) {
97
+ select.value = self.options.savedDefaultFormId;
98
+ self.options.savedDefaultFormId = false;
99
+ }
100
+ }
101
+ });
102
+ } else {
103
+ this.resetFormList();
104
+ }
105
+ },
106
+ changeSubGroup: function (element)
107
+ {
108
+ var selectedValue = element.value,
109
+ id = element.id.replace("_crconnect", ""),
110
+ key = $("crroot_crconnect_api_key").value,
111
+ url = this.options.baseChangeGroupUrl + 'group/' + selectedValue + '/crconnectkey/' + key,
112
+ self = this;
113
+
114
+ new Ajax.Request(url, {
115
+ method: 'get',
116
+ onSuccess: function (transport) {
117
+ var select = $(id + '_formid');
118
+ self.cleanSelect(id + '_formid');
119
+ if (transport.responseText == "empty") {
120
+ self.resetFormList(id + '_formid');
121
+ return false;
122
+ }
123
+ var editData = transport.responseText.evalJSON(true);
124
+ select.insert(new Element('option', {
125
+ value: ''
126
+ }).update(Translator.translate('Please select form')));
127
+ for (var i = 0; i < editData.length; i++) {
128
+ select.insert(new Element('option', {
129
+ value: editData[i].id
130
+ }).update(editData[i].name));
131
+ }
132
+
133
+ if (self.options.savedFormsKeys) {
134
+ if (self.options.savedFormsKeys[id]) {
135
+ select.value = self.options.savedFormsKeys[id];
136
+ }
137
+ }
138
+ }
139
+ });
140
+ },
141
+ confirmEnable: function ()
142
+ {
143
+ $("confirm-key-button").removeClassName('disabled');
144
+ $("confirm-key-button").disabled = false;
145
+ },
146
+ confirmDisable: function ()
147
+ {
148
+ $("confirm-key-button").addClassName('disabled');
149
+ $("confirm-key-button").disabled = true;
150
+ },
151
+ resetFormList: function (formId)
152
+ {
153
+ if (!formId) {
154
+ formId = 'crroot_crconnect_form_id';
155
+ }
156
+ this.cleanSelect(formId);
157
+ $(formId).insert(new Element('option', {
158
+ value: ''
159
+ }).update(Translator.translate('No forms to select')));
160
+ },
161
+ resetGroupList: function (formId)
162
+ {
163
+ if (!formId) {
164
+ formId = 'crroot_crconnect_list_id';
165
+ }
166
+ this.cleanSelect(formId);
167
+ $(formId).insert(new Element('option', {
168
+ value: ''
169
+ }).update(Translator.translate('No groups to select')));
170
+ },
171
+ cleanSelect: function (selectId)
172
+ {
173
+ var options = $$('select#' + selectId + ' option');
174
+ for (var i = 0; i < options.length; i++) {
175
+ options[i].remove();
176
+ }
177
+ },
178
+ fillSelectedGroups: function ()
179
+ {
180
+ if (typeof this.elements.editedSelects != "undefined") {
181
+ if (this.elements.editedSelects.length > 0) {
182
+ for (var i = 0; i < this.elements.editedSelects.length; i++) {
183
+ this.changeSubGroup($(this.elements.editedSelects[i] + "_crconnect"));
184
+ }
185
+ }
186
+ }
187
+ }
188
+ };
189
+
190
+ function initCleverReach()
191
+ {
192
+ try {
193
+ var CrC = new Crconnect(crconnectOptions, crconnectElements);
194
+ CrC.confirmMainKey();
195
+ Event.observe('crroot_crconnect_api_key', 'keyup', function () { CrC.confirmEnable(); });
196
+ Event.observe('crroot_crconnect_list_id', 'change', function () { CrC.changeGroupId(); });
197
+ CrC.fillSelectedGroups();
198
+ } catch (e) {
199
+ console.log(e);
200
+ }
201
+ }
202
+ Event.observe(window, 'load', initCleverReach);