gd-sprest-js
Version:
SharePoint 2013/Online js components.
65 lines (64 loc) • 2.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var _1 = require(".");
/**
* Persona
*/
exports.Persona = function (props) {
// Render the persona
props.el.innerHTML = _1.Templates.Persona(props.userInfo);
// See if a click event exists
if (props.onCancel) {
// Get the cancel icon
var elIcon = props.el.querySelector("ms-Icon--Cancel");
// Set the click event
elIcon.addEventListener("click", function () {
// Clear the persona
props.el.innerHTML = "";
// Call the event
props.onCancel(props.userInfo);
});
}
// Return the persona
return props.el;
};
/**
* Personas
*/
exports.Personas = function (props) {
// Clear the element
props.el.innerHTML = "";
// Parse the personas
for (var i = 0; i < props.userInfo.length; i++) {
// Create the persona
var el = document.createElement("div");
el.innerHTML = _1.Templates.Persona(props.userInfo[i]);
el.children[0].setAttribute("data-idx", i.toString());
// Set the index of the cancel icon
var elCancel = el.querySelector(".ms-Icon--Cancel");
elCancel.setAttribute("data-idx", i.toString());
// Append the persona
props.el.appendChild(el.children[0]);
}
// Get the cancel icons
var elIcons = props.el.querySelectorAll(".ms-Icon--Cancel");
for (var i = 0; i < elIcons.length; i++) {
// Set the click event
elIcons[i].addEventListener("click", function (ev) {
// Get the index
var idx = ev.currentTarget.getAttribute("data-idx");
// Parse the personas
for (var i_1 = 0; i_1 < props.el.children.length; i_1++) {
// See if this is the target index
if (props.el.children[i_1].getAttribute("data-idx") == idx) {
// Remove the element
props.el.removeChild(props.el.children[i_1]);
// Call the click event
props.onCancel(props.userInfo[parseInt(idx)]);
}
}
});
}
// Return the personas
return props.el;
};