UNPKG

gd-sprest-js

Version:

SharePoint 2013/Online js components.

151 lines (150 loc) 5.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var gd_sprest_1 = require("gd-sprest"); var Fabric = require("../../fabric"); /** * List WebPart Edit Panel */ exports.WPListEditPanel = function (props) { if (props === void 0) { props = {}; } var _elFooter = null; var _elList = null; var _elWebUrl = null; var _initFl = false; var _lists = null; var _wpInfo = null; // Method to load the lists var loadLists = function (webUrl) { // Set the query var query = props.listQuery || {}; // Render a loading message Fabric.Spinner({ el: _elList, text: "Loading the lists..." }); // Get the web gd_sprest_1.Web(webUrl) // Get the lists .Lists() // Include the fields .query(query) // Execute the request .execute(function (lists) { // Save the lists _lists = lists.results; // Call the list rendering event _lists = (props.onListsRendering ? props.onListsRendering(_wpInfo, _lists) : null) || _lists; // Render the list dropdown renderListDDL(); }); }; // Method to render the configuration var renderConfiguration = function (el, wpInfo) { // Render the panel contents el.innerHTML = [ '<div></div>', '<div></div>' ].join('\n'); _elWebUrl = el.children[0]; _elList = el.children[1]; // Render the web url textbox var webUrl = _wpInfo && _wpInfo.cfg ? _wpInfo.cfg.WebUrl : ""; Fabric.TextField({ el: _elWebUrl, label: "Relative Web Url:", description: "The web containing the list. If blank, the current web is used.", value: webUrl, onChange: function (value) { // Update the configuration _wpInfo.cfg.WebUrl = value; } }); // Load the lists loadLists(webUrl); }; // Method to render the lists dropdown var renderListDDL = function () { var selectedList = null; var options = []; // Parse the lists for (var i = 0; i < _lists.length; i++) { var list = _lists[i]; // Add the option options.push({ text: list.Title, value: list.Title }); // See if this is the selected list if (list.Title == _wpInfo.cfg.ListName) { // Select this list selectedList = list; } } // Render the dropdown var ddl = Fabric.Dropdown({ el: _elList, label: "List:", options: options, value: _wpInfo && _wpInfo.cfg ? _wpInfo.cfg.ListName : null, onChange: function (options) { var option = options[0]; if (option) { // Parse the list for (var i = 0; i < _lists.length; i++) { var list = _lists[i]; // See if this is the target list if (list.Title == option.text) { // Update the configuration _wpInfo.cfg.ListName = option.value; // Call the change event props.onListChanged ? props.onListChanged(_wpInfo, list) : null; break; } } } } }); // Call the render footer event props.onRenderFooter ? props.onRenderFooter(_elFooter, _wpInfo, selectedList) : null; }; // Create the menu commands var menuLeftCommands = [ { icon: "Refresh", text: "Refresh", onClick: function () { // Load the lists loadLists(_wpInfo.cfg.WebUrl); } } ]; // See if custom commands exist if (props.menuLeftCommands) { // Add the custom commands menuLeftCommands = menuLeftCommands.concat(props.menuLeftCommands); } // Return the edit panel return { menuLeftCommands: menuLeftCommands, menuRightCommands: props.menuRightCommands, onRenderHeader: props.onRenderHeader, panelType: props.panelType, showSaveButton: props.showSaveButton, onRenderFooter: function (el, wpInfo) { // Save the webpart information _wpInfo = wpInfo; // Render the template el.innerHTML = "<div></div><div></div>"; _elFooter = el.children[1]; // Render the configuration renderConfiguration(el.children[0], wpInfo); }, onSave: function (cfg) { // Update the configuration cfg.ListName = _wpInfo.cfg.ListName; cfg.WebUrl = _wpInfo.cfg.WebUrl; // Return the configuration return props.onSave ? props.onSave(_wpInfo.cfg) : _wpInfo.cfg; } }; };