1 /** 2 * @fileOverview 3 * @author <a href="https://www.labkey.org">LabKey</a> (<a href="mailto:info@labkey.com">info@labkey.com</a>) 4 * @license Copyright (c) 2009-2016 LabKey Corporation 5 * <p/> 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * <p/> 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * <p/> 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * <p/> 18 */ 19 20 /** 21 * @namespace Participant group static class to update participant group information. 22 * <p>Additional Documentation: 23 * <ul> 24 * </ul> 25 * </p> 26 */ 27 LABKEY.ParticipantGroup = new function() 28 { 29 function getSuccessCallbackWrapper(successCallback, rootProperty) 30 { 31 return LABKEY.Utils.getCallbackWrapper(function(data){ 32 successCallback(rootProperty ? data[rootProperty] : data); 33 }, this); 34 } 35 36 function sendJsonQueryRequest(config) { 37 LABKEY.Ajax.request({ 38 url : config.url, 39 method : config.method || 'POST', 40 success : config.success, 41 failure : config.failure, 42 jsonData : config.jsonData, 43 headers : { 44 'Content-Type' : 'application/json' 45 } 46 }); 47 } 48 49 /** @scope LABKEY.ParticipantGroup */ 50 return { 51 // UpdateParticipantGroupAction 52 /** 53 * Updates an existing participant group, already saved and accessible to the current user on the server. 54 * @param {Object} config An object which contains the following configuration properties. The group properties 55 * are not included in the config, their values will remain unchanged. 56 * @param {Function} config.success Required. Function called when the 57 request executes successfully. Will be called with the arguments: 58 <ul> 59 <li>group: the new state of the participant group, with properties rowId, participantIds, label and description. 60 <li>response: the full response object from the AJAX request. 61 </ul> 62 * @param {Function} [config.failure] Function called when execution of the request fails. 63 * @param {int} config.rowId The integer ID of the desired participant group 64 * @param {Array} [config.participantId] Set of IDs to be members of the group 65 * @param {Array} [config.ensureParticipantIds] Set of IDs to be added to the group if they are not already members 66 * @param {Array} [config.deleteParticipantIds] Set of IDs to be removed from the group if they are already members 67 * @param {Array} [config.label] The new value for the label of the group 68 * @param {Array} [config.description] The new value for the description of the group 69 * @param {String} [config.containerPath] The container path in which the relevant study is defined. 70 * If not supplied, the current container path will be used. 71 */ 72 updateParticipantGroup : function(config) 73 { 74 var group = {}; 75 if (config.rowId) { 76 group.rowId = config.rowId; 77 } 78 if (config.participantIds) { 79 group.participantIds = config.participantIds; 80 } 81 if (config.ensureParticipantIds) { 82 group.ensureParticipantIds = config.ensureParticipantIds; 83 } 84 if (config.deleteParticipantIds) { 85 group.deleteParticipantIds = config.deleteParticipantIds; 86 } 87 if (config.label) { 88 group.label = config.label; 89 } 90 if (config.description) { 91 group.description = config.description; 92 } 93 if (config.filters) { 94 group.filters = config.filters; 95 } 96 97 sendJsonQueryRequest({ 98 url : LABKEY.ActionURL.buildURL("participant-group", "updateParticipantGroup.api", config.containerPath), 99 success: getSuccessCallbackWrapper(config.success, 'group'), 100 failure: LABKEY.Utils.getCallbackWrapper(config.failure, this, true), 101 jsonData : group 102 }); 103 } 104 }; 105 }; 106 107 /**#@-*/ 108