1 /*********************************************************************************
2 * SugarCRM Community Edition is a customer relationship management program developed by
3 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Affero General Public License version 3 as published by the
7 * Free Software Foundation with the addition of the following permission added
8 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
9 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
10 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
17 * You should have received a copy of the GNU Affero General Public License along with
18 * this program; if not, see http://www.gnu.org/licenses or write to the Free
19 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
23 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
25 * The interactive user interfaces in modified source and object code versions
26 * of this program must display Appropriate Legal Notices, as required under
27 * Section 5 of the GNU Affero General Public License version 3.
29 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
30 * these Appropriate Legal Notices must retain the display of the "Powered by
31 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
32 * technical reasons, the Appropriate Legal Notices must display the words
33 * "Powered by SugarCRM".
34 ********************************************************************************/
37 <script src="http://yui.yahooapis.com/2.6.0/build/yahoo/yahoo-min.js"></script>
38 <!-- Used for Custom Events and event listener bindings -->
39 <script src="http://yui.yahooapis.com/2.6.0/build/event/event-min.js"></script>
41 <script src="http://yui.yahooapis.com/2.6.0/build/connection/connection-min.js"></script>
42 <script src="http://yui.yahooapis.com/2.6.0/build/json/json-min.js"></script>
44 var SugarRest = function(){}
46 SugarRest.callCount = -1;
47 SugarRest.startTest = function(name, password){
48 SugarRest.callCount = 1;
49 SugarRest.login(name, password, 'JAVASCRIPT TEST');
51 SugarRest.test = function(o){
52 data = SugarRest.logResponse(o);
53 switch(SugarRest.callCount){
55 SugarRest.callCount++;
56 SugarRest.getServerInfo();
57 SugarRest.session = data['id'];
60 SugarRest.callCount++;
61 SugarRest.getUserId();
64 SugarRest.callCount++;
65 SugarRest.getEntry('Contacts', '17700cb1-9da0-f511-f9d7-490b635b9ead');
68 SugarRest.callCount++;
69 SugarRest.getEntryList('Contacts');
72 SugarRest.callCount++;
73 SugarRest.getModuleFields('Contacts', []);
76 SugarRest.callCount++;
77 SugarRest.getEntries('Contacts', ['17700cb1-9da0-f511-f9d7-490b635b9ead', '177cf935-e488-04c3-7af3-490b632b4ab0']);
80 SugarRest.callCount++;
81 SugarRest.setRelationship('Accounts', 'mastd368-c7er-cof8-16pu-47d57b16pets', 'contacts', ['2f043319-7cb0-6bfa-75d3-490b63fa6c08', 'c57d7598-42e6-cca8-a302-490b63118b48']);
84 SugarRest.callCount++;
85 SugarRest.setRelationships(['Accounts', 'Contacts'], ['mastd368-c7er-cof8-16pu-47d57b16pets', '2f043319-7cb0-6bfa-75d3-490b63fa6c08'], ['contacts', 'opportunities'], [['2f043319-7cb0-6bfa-75d3-490b63fa6c08'], ['52acdc25-6a6e-a574-6936-490b63fbc1df']]);
88 SugarRest.callCount++;
89 SugarRest.getRelationships('Accounts', 'mastd368-c7er-cof8-16pu-47d57b16pets', 'contacts', '', ['first_name', 'last_name', 'primary_address_city'], [{'name' : 'opportunities', 'value' : ['name', 'type', 'lead_source']}, {'name' : 'email_addresses', 'value' : ['id', 'email_address', 'opt_out', 'primary_address']}], 0);
92 SugarRest.callCount++;
93 SugarRest.setEntry('Accounts', [{'name' : 'city', 'value' : 'SFO'},
94 {'name' : 'name', 'value' : 'DCE Puppet Master111'}]);
97 SugarRest.callCount++;
98 SugarRest.setEntries('Accounts', [[{'name' : 'city', 'value' : 'SFO'},
99 {'name' : 'name', 'value' : 'Acc1'}], [{'name' : 'city', 'value' : 'SFO'},
100 {'name' : 'name', 'value' : 'Acc2'}]]);
103 SugarRest.callCount++;
104 SugarRest.seamlessLogin();
107 SugarRest.callCount++;
108 SugarRest.setNoteAttachment({'id' : 'bb79c0f3-78e1-c6fc-2c41-490b636653c0', 'related_module_id' : '3d921d14-047f-cc7d-1988-490b63592ae8', 'related_module_name' : 'Accounts'});
111 SugarRest.callCount++;
112 SugarRest.getNoteAttachment('bb79c0f3-78e1-c6fc-2c41-490b636653c0');
115 SugarRest.callCount++;
116 SugarRest.getDocumentRevision('ab18578e-17f5-5fc0-96ba-4925a9baaa20');
119 SugarRest.callCount++;
120 SugarRest.search('admin', '21232f297a57a5a743894a0e4a801fc3', 'a', ['Accounts', 'Contacts'], 0, 5);
124 SugarRest.callCount++;
125 SugarRest.setDocumentRevision({'id' : '8d7f0917-19d3-9f88-80d7-49121ddb62e2','document_name' : 'test doc',
127 'filename' : 'code1.txt',
128 'file' : 'JHFzID0gJyc7DQppZiAoaXNzZXQoJF9TRVJWRVJbJ1FVRVJZX1NUUklORyddKSkgew0KCSRxcyA9ICRfU0VSVkVSWydRVUVSWV9TVFJJTkcnXTsNCn0gZWxzZWlmIChpc3NldCgkSFRUUF9TRVJWRVJfVkFSU1snUVVFUllfU1RSSU5HJ10pKSB7DQoJJHFzID0gJEhUVFBfU0VSVkVSX1ZBUlNbJ1FVRVJZX1NUUklORyddOw0KfSBlbHNlIHsNCgkkcXMgPSAnJzsNCn0NCg0KJHQxID0gc3RydG90aW1lKCJub3ciKTsNCg0KaWYgKGVyZWcoJ3dzZGwnLCAkcXMpICl7DQoJZ2xvYmFsICRzdWdhcl9jb25maWc7DQoJJHVwbG9hZERpciA9ICRzdWdhcl9jb25maWdbJ3VwbG9hZF9kaXInXTsNCgkkd3NkbFVSTCA9ICRzdWdhcl9jb25maWdbJ3NpdGVfdXJsJ10uJy9zb2FwLnBocD93c2RsJzsNCgkkd3NkbENhY2hlRmlsZSA9ICR1cGxvYWREaXIuJy93c2R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
144 var returndata = 'method=' + method_name + '&input_type=json&response_type=json';
146 returndata = returndata + '&rest_data=' + data;
150 SugarRest.logResponse = function(o){
152 data = YAHOO.lang.JSON.parse(o.responseText);
157 SugarRest.getServerInfo = function(){
158 console.log('Getting Server Info');
159 YAHOO.util.Connect.asyncRequest('POST', 'v2/rest.php' , {success:SugarRest.test, failure:SugarRest.test}, SugarRest.getRequestData('get_server_info'));
162 SugarRest.getModuleFields = function(module, fields){
163 console.log('Getting Server Info');
164 var data = [SugarRest.session, module, fields];
165 m = YAHOO.lang.JSON.stringify(data);
166 YAHOO.util.Connect.asyncRequest('POST', 'v2/rest.php' , {success:SugarRest.test, failure:SugarRest.test}, SugarRest.getRequestData('get_module_fields', m));
169 SugarRest.login = function(name, password, application){
170 console.log('Logging In');
173 password: '21232f297a57a5a743894a0e4a801fc3'
175 m = YAHOO.lang.JSON.stringify(loginData);
176 YAHOO.util.Connect.asyncRequest('POST', 'v2/rest.php' , {success:SugarRest.test, failure:SugarRest.test}, SugarRest.getRequestData('login', m));
179 SugarRest.getUserId = function(){
180 console.log('Getting User Id ');
181 m = YAHOO.lang.JSON.stringify(SugarRest.session);
182 YAHOO.util.Connect.asyncRequest('POST', 'v2/rest.php' , {success:SugarRest.test, failure:SugarRest.test}, SugarRest.getRequestData('get_user_id', m));
186 SugarRest.getEntryList = function(module){
187 var data = [SugarRest.session, module, "", '', 0, [], [{
188 'name': 'email_addresses',
189 'value': ['id', 'email_address', 'opt_out', 'primary_address',]
191 m = YAHOO.lang.JSON.stringify(data);
192 YAHOO.util.Connect.asyncRequest('POST', 'v2/rest.php', {
193 success: SugarRest.test,
194 failure: SugarRest.test
195 }, SugarRest.getRequestData('get_entry_list', m));
199 SugarRest.getEntry = function(module, id){
200 var data = [SugarRest.session, module, id, ['last_name', 'email1', 'date_modified','description'], [{
201 'name': 'email_addresses',
202 'value': ['id', 'email_address', 'opt_out', 'primary_address',]
204 m = YAHOO.lang.JSON.stringify(data);
205 YAHOO.util.Connect.asyncRequest('POST', 'v2/rest.php', {
206 success: SugarRest.test,
207 failure: SugarRest.test
208 }, SugarRest.getRequestData('get_entry', m));
211 SugarRest.getEntries = function(module, ids){
212 var data = [SugarRest.session, module, ids, ['last_name', 'email1', 'date_modified','description'], [{
213 'name': 'email_addresses',
214 'value': ['id', 'email_address', 'opt_out', 'primary_address',]
216 m = YAHOO.lang.JSON.stringify(data);
217 YAHOO.util.Connect.asyncRequest('POST', 'v2/rest.php', {
218 success: SugarRest.test,
219 failure: SugarRest.test
220 }, SugarRest.getRequestData('get_entries', m));
223 SugarRest.setRelationship = function(module, module_id, link_field_name, related_ids){
224 var data = [SugarRest.session, module, module_id, link_field_name, related_ids];
225 m = YAHOO.lang.JSON.stringify(data);
226 YAHOO.util.Connect.asyncRequest('POST', 'v2/rest.php', {
227 success: SugarRest.test,
228 failure: SugarRest.test
229 }, SugarRest.getRequestData('set_relationship', m));
232 SugarRest.setRelationships = function(modules, module_ids, link_field_names, related_ids){
233 var data = [SugarRest.session, modules, module_ids, link_field_names, related_ids];
234 m = YAHOO.lang.JSON.stringify(data);
235 YAHOO.util.Connect.asyncRequest('POST', 'v2/rest.php', {
236 success: SugarRest.test,
237 failure: SugarRest.test
238 }, SugarRest.getRequestData('set_relationships', m));
241 SugarRest.getRelationships = function(module, module_id, link_field_name, related_module_query, related_fields, related_module_link_name_to_fields_array, deleted){
242 var data = [SugarRest.session, module, module_id, link_field_name, related_module_query, related_fields, related_module_link_name_to_fields_array, deleted];
243 m = YAHOO.lang.JSON.stringify(data);
244 YAHOO.util.Connect.asyncRequest('POST', 'v2/rest.php', {
245 success: SugarRest.test,
246 failure: SugarRest.test
247 }, SugarRest.getRequestData('get_relationships', m));
250 SugarRest.setEntry = function(module, name_value_list){
251 var data = [SugarRest.session, module, name_value_list];
252 m = YAHOO.lang.JSON.stringify(data);
253 YAHOO.util.Connect.asyncRequest('POST', 'v2/rest.php', {
254 success: SugarRest.test,
255 failure: SugarRest.test
256 }, SugarRest.getRequestData('set_entry', m));
259 SugarRest.setEntries = function(module, name_value_lists){
260 var data = [SugarRest.session, module, name_value_lists];
261 m = YAHOO.lang.JSON.stringify(data);
262 YAHOO.util.Connect.asyncRequest('POST', 'v2/rest.php', {
263 success: SugarRest.test,
264 failure: SugarRest.test
265 }, SugarRest.getRequestData('set_entries', m));
268 SugarRest.seamlessLogin = function(){
269 var data = [SugarRest.session];
270 m = YAHOO.lang.JSON.stringify(data);
271 YAHOO.util.Connect.asyncRequest('POST', 'v2/rest.php', {
272 success: SugarRest.test,
273 failure: SugarRest.test
274 }, SugarRest.getRequestData('seamless_login', m));
277 SugarRest.setNoteAttachment = function(noteObject){
278 var data = [SugarRest.session, noteObject];
279 m = YAHOO.lang.JSON.stringify(data);
280 YAHOO.util.Connect.asyncRequest('POST', 'v2/rest.php', {
281 success: SugarRest.test,
282 failure: SugarRest.test
283 }, SugarRest.getRequestData('set_note_attachment', m));
286 SugarRest.getNoteAttachment = function(noteId){
287 var data = [SugarRest.session, noteId];
288 m = YAHOO.lang.JSON.stringify(data);
289 YAHOO.util.Connect.asyncRequest('POST', 'v2/rest.php', {
290 success: SugarRest.test,
291 failure: SugarRest.test
292 }, SugarRest.getRequestData('get_note_attachment', m));
295 SugarRest.setDocumentRevision = function(revisionObject){
296 var data = [SugarRest.session, revisionObject];
297 m = YAHOO.lang.JSON.stringify(data);
298 YAHOO.util.Connect.asyncRequest('POST', 'v2/rest.php', {
299 success: SugarRest.test,
300 failure: SugarRest.test
301 }, SugarRest.getRequestData('set_document_revision', m));
304 SugarRest.getDocumentRevision = function(docRevId){
305 var data = [SugarRest.session, docRevId];
306 m = YAHOO.lang.JSON.stringify(data);
307 YAHOO.util.Connect.asyncRequest('POST', 'v2/rest.php', {
308 success: SugarRest.test,
309 failure: SugarRest.test
310 }, SugarRest.getRequestData('get_document_revision', m));
313 SugarRest.search = function(username, password, search_string, modules_to_search, offset, maxresults){
314 var data = [username, password, search_string, modules_to_search, offset, maxresults];
315 m = YAHOO.lang.JSON.stringify(data);
316 YAHOO.util.Connect.asyncRequest('POST', 'v2/rest.php', {
317 success: SugarRest.test,
318 failure: SugarRest.test
319 }, SugarRest.getRequestData('search_by_module', m));
321 SugarRest.startTest();