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) 2015-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 The List namespace allows you to create new Lists. 22 * @ignore hide from JsDoc for now 23 */ 24 LABKEY.List = new function () { 25 "use strict"; 26 27 /** @scope LABKEY.List */ 28 return { 29 30 /** 31 * Create a new list. 32 * A primary key column must be specified with the properties 'keyName' and 'keyType'. If the key 33 * is not provided in the domain design's array of fields, it will be automatically added to the domain. 34 * 35 * @ignore hide from JsDoc for now 36 * 37 * @param config A config object with properties from {@link LABKEY.Domain.DomainDesign} and the following additional properties: 38 * @param config.name The list name. 39 * @param config.keyName The name of the key column. 40 * @param config.keyType The type of the key column. Either "int" or "string". 41 * @example 42 * <pre> 43 * LABKEY.List.create({ 44 * name: "mylist", 45 * keyType: "int", 46 * keyName: "one", 47 * description: "my first list", 48 * fields: [{ 49 * name: "one", rangeURI: "int" 50 * },{ 51 * name: "two", rangeURI: "multiLine", required: true 52 * },{ 53 * name: "three", rangeURI: "Attachment" 54 * }] 55 * }); 56 * </pre> 57 */ 58 create : function (config) { 59 var createConfig = { 60 domainDesign: config, 61 options: {} 62 }; 63 64 if (!createConfig.domainDesign.name) 65 throw new Error("List name required"); 66 67 if (!config.kind) 68 { 69 if (config.keyType == "int") 70 config.kind = "IntList"; 71 else if (config.keyType == "string") 72 config.kind = "VarList"; 73 } 74 75 if (config.kind != "IntList" && config.kind != "VarList") 76 throw new Error("Domain kind or keyType required"); 77 createConfig.kind = config.kind; 78 79 if (!config.keyName) 80 throw new Error("List keyName required"); 81 createConfig.options.keyName = config.keyName; 82 83 // TODO: other list design options 84 85 LABKEY.Domain.create(createConfig); 86 } 87 88 } 89 }; 90