gd-sprest-js
Version:
SharePoint 2013/Online js components.
138 lines (137 loc) • 4.82 kB
JavaScript
;
var _this = this;
Object.defineProperty(exports, "__esModule", { value: true });
var gd_sprest_1 = require("gd-sprest");
var Fabric = require("../../fabric");
/**
* Search WebPart Edit Panel
*/
exports.WPSearchEditPanel = function (props) {
if (props === void 0) { props = {}; }
var _elFieldsDDL = null;
var _wpInfo = null;
// Method to render the fields
var renderFields = function (el, list) {
// Render the fields
_this.el = el;
el.innerHTML = "<div></div><div></div>";
var _elFieldsDDL = el.children[0];
// Ensure the list exists
if (list == null) {
return;
}
// Render a spinner
Fabric.Spinner({
el: _elFieldsDDL,
text: "Loading the fields..."
});
// Load the fields dropdown list
renderFieldsDDL(list);
// Call the custom event
props.onRenderFooter ? props.onRenderFooter(el.children[1], _wpInfo, list) : null;
};
// Method to render the fields drop down list
var renderFieldsDDL = function (list) {
var options = [];
// Parse the fields
var fields = (list.Fields ? list.Fields.results : null) || [];
for (var i = 0; i < fields.length; i++) {
var addField = false;
var field = fields[i];
// Add the field, based on the type
switch (field.FieldTypeKind) {
// Searchable Fields
case gd_sprest_1.SPTypes.FieldType.Choice:
case gd_sprest_1.SPTypes.FieldType.MultiChoice:
case gd_sprest_1.SPTypes.FieldType.Lookup:
case gd_sprest_1.SPTypes.FieldType.Text:
case gd_sprest_1.SPTypes.FieldType.URL:
case gd_sprest_1.SPTypes.FieldType.User:
addField = true;
break;
default:
// Allow managed metadata fields
addField = field.TypeAsString.startsWith("TaxonomyFieldType");
break;
}
// See if we are adding the field
if (addField) {
options.push({
data: field.TypeAsString,
text: field.Title + " [" + field.InternalName + "]",
value: field.InternalName
});
}
}
// Sort the options
options = options.sort(function (a, b) {
if (a.value < b.value) {
return -1;
}
if (a.value > b.value) {
return 1;
}
return 0;
});
// See if fields exist
var value = [];
if (_wpInfo.cfg && _wpInfo.cfg.Fields) {
// Parse the fields
for (var i = 0; i < _wpInfo.cfg.Fields.length; i++) {
// Add the field
value.push(_wpInfo.cfg.Fields[i].name);
}
}
// Render the field dropdown
Fabric.Dropdown({
el: _elFieldsDDL,
label: "Filter Field(s):",
multi: true,
options: options,
value: value,
onChange: function (options) {
// Clear the fields
_wpInfo.cfg.Fields = [];
// Parse the options
for (var i = 0; i < options.length; i++) {
var option = options[i];
// Add the field
_wpInfo.cfg.Fields.push({
name: option.value,
type: option.data
});
}
}
});
};
// Set the list query
var listQuery = props.listQuery || {};
listQuery.Expand = listQuery.Expand || [];
listQuery.Expand.push("Fields");
// Return the edit panel
return {
listQuery: listQuery,
menuLeftCommands: props.menuLeftCommands,
menuRightCommands: props.menuRightCommands,
onListsRendering: props.onListsRendering,
onRenderHeader: props.onRenderHeader,
panelType: props.panelType,
showSaveButton: props.showSaveButton,
onListChanged: function (wpInfo, list) {
// Render the fields
renderFields(_this.el.children[0], list);
},
onRenderFooter: function (el, wpInfo, list) {
// Save the webpart information
_wpInfo = wpInfo;
// Render the fields
renderFields(el, list);
},
onSave: function (cfg) {
// Update the configuration
cfg.Fields = _wpInfo.cfg.Fields || [];
// Return the configuration
return props.onSave ? props.onSave(_wpInfo.cfg) : _wpInfo.cfg;
}
};
};