gd-sprest-bs
Version:
SharePoint JavaScript, TypeScript and Web Components designed using the Bootstrap framework.
86 lines (85 loc) • 3.42 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.Dropdown = exports._Dropdown = void 0;
var core_1 = require("../components/core");
var base_1 = require("./base");
/**
* Dropdown
*/
var _Dropdown = /** @class */ (function (_super) {
__extends(_Dropdown, _super);
function _Dropdown() {
return _super !== null && _super.apply(this, arguments) || this;
}
// Internal rendering event
_Dropdown.prototype.onRendering = function (props) { return props; };
// Override the render event
_Dropdown.prototype.onRender = function (el, context, onChange) {
var _this = this;
var currentValue = this.currentValueAsObject();
if (currentValue) {
var values = [];
// Parse the values
for (var i = 0; i < currentValue.length; i++) {
values.push(currentValue[i]["value"] || currentValue[i]["text"] || currentValue[i]["label"]);
}
// Update the current value
currentValue = values;
}
// Set the properties
var config = this.config;
var props = {
description: config.description,
items: config.items,
label: config.label,
name: this.targetProperty,
type: core_1.Components.FormControlTypes.Dropdown,
value: currentValue,
onChange: function (item) {
// Convert the object as a string
var value = undefined;
try {
value = JSON.stringify(item);
}
catch (_a) { }
// Call the event
value = config.onSave ? config.onSave(value) : value;
// Update the property
onChange(_this.targetProperty, value);
}
};
// Call the rendering events
props = this.onRendering(props);
props = config.onRendering ? config.onRendering(props) : props;
// Render the dropdown
core_1.Components.Form({
el: el,
controls: [props],
onControlRendered: function (ctrl) {
// Call the event
config.onRendered ? config.onRendered(ctrl.dropdown, ctrl.props) : null;
}
});
};
return _Dropdown;
}(base_1.BasePropertyPane));
exports._Dropdown = _Dropdown;
var Dropdown = function (targetProperty, config, context) {
return new _Dropdown(targetProperty, config, context);
};
exports.Dropdown = Dropdown;