Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Some variables I removed
- $(document).ready(function () {
- writeAction();
- writeTabs();
- $("#DeltaPlaceHolderPageTitleInTitleArea").html("AKG Startseite");
- $(".ms-breadcrumb-top").hide();
- // $(".ms-core-listMenu-root").hide();
- //$("#zz17_RootAspMenu").hide();
- $(".ms-mpSearchBox").hide();
- $(".DeltaPlaceHolderSearchArea").hide();
- //$("#titleAreaRow").hide();
- $("#Ribbon.ListForm.Display.Manage.EditItem-Large").hide();
- $("#fullscreenmode").click();
- window.setTimeout(showTabsBasedOnGroup, 3000);
- checkAkgLink();
- });
- function checkNull(chValue) {
- if (chValue == null) {
- return "";
- } else {
- return chValue;
- }
- }
- function writeAction() {
- var outHtml = "<a href=\"javascript:createNewAKG();\">" + imgAdd + " " + unescape("Neues AKG anlegen") + "</a>";
- outHtml += " <a href=\"javascript:refresh();\">" + imgRefresh + " " + unescape("Aktualisieren") + "</a>";
- outHtml += " <a href=\"https://thesite?objid=4515\" target=\"_blank\">" + " " + unescape("Führung von Auftragsklärungsgesprächen") + "</a>";
- $("#startTableAction").html(outHtml);
- }
- function getListItems(url) {
- return $.ajax({
- url: _spPageContextInfo.webAbsoluteUrl + url,
- type: 'GET',
- headers: {
- "Accept": "application/json; odata=verbose"
- },
- success: function (data) {
- },
- error: function (XMLHttpRequest, textStatus, errorThrown) {
- console.log("Status: " + textStatus); alert("Error: " + errorThrown);
- }
- });
- }
- function getCurrentUserProfileCity() {
- return new Promise(function(resolve, reject) {
- $.ajax({
- url:_spPageContextInfo.webAbsoluteUrl + "/_api/SP.UserProfiles.PeopleManager/GetMyProperties",
- type:"GET",
- contentType : "application/json;odata=verbose",
- headers: {
- "accept": "application/json;odata=verbose",
- "X-RequestDigest": $("#__REQUESTDIGEST").val()
- },
- success:function(data){
- var location = data.d.UserProfileProperties.results.filter(function(element) {
- return element.Key==="SPS-Location";
- })[0].Value;
- resolve(location);
- },
- error:function(jqxr){
- console.log(jqxr.responseText);
- reject();
- }
- });
- });
- }
- function CreateListItemWithDetails(listName, success, failure) {
- currentUserProfileCity
- .then(function(city){
- var item = {
- "__metadata": { "type": "SP.Data.AKGListItem" },
- "ProjektleiterId": _spPageContextInfo.userId,
- "Standort": city,
- "ExcelExport": "<DIV class='opexcelexport'>ID</DIV>"
- };
- //add set origID to ID
- //set Export to <DIV class='opexcelexport'>ID</DIV>
- $.ajax({
- url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('" + listName + "')/items",
- type: "POST",
- contentType: "application/json;odata=verbose",
- data: JSON.stringify(item),
- headers: {
- "accept": "application/json;odata=verbose",
- "X-RequestDigest": $("#__REQUESTDIGEST").val()
- },
- success: function (data)
- {
- refresh();
- success(data);
- },
- error: function (data)
- {
- failure(data);
- }
- });
- });
- }
- function deleteListItemsBatch(listTitle, refId) {
- var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('" + listTitle + "')/items?&$filter=refID eq " + refId;
- return $.ajax({
- url: url,
- type: "GET",
- headers: { "Accept": "application/json;odata=verbose" }
- })
- .then(function(data) {
- var items = data.d.results;
- var updateBatchValue = '<Batch OnError="Continue">';
- for(var i = 0; i < items.length; i++){
- var currentItem = items[i];
- updateBatchValue += '<Method ID="' + (currentItem.ID || currentItem.Id) + '" Cmd="Delete"><Field Name="ID">' + (currentItem.ID || currentItem.Id) + '</Field></Method>';
- }
- updateBatchValue += '</Batch>';
- var soapEnv =
- '<?xml version="1.0" encoding="utf-8"?>' +
- '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
- '<soap:Body>' +
- '<UpdateListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">' +
- '<listName>' + listTitle + '</listName>' +
- '<updates>' + updateBatchValue + '</updates>' +
- '</UpdateListItems>' +
- '</soap:Body>' +
- '</soap:Envelope>';
- return soapEnv;
- })
- .then(function(soapEnv) {
- url = _spPageContextInfo.webAbsoluteUrl + '/_vti_bin/lists.asmx';
- $.ajax({
- url: url,
- beforeSend: function(xhr) { xhr.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/UpdateListItems");},
- type: "POST",
- dataType: "xml",
- data: soapEnv,
- contentType: "text/xml; charset=\"utf-8\"",
- success: function () {
- },
- error: function (XMLHttpRequest, textStatus, errorThrown) {
- console.log("Status: " + textStatus); alert("Error: " + errorThrown);
- }
- });
- });
- }
- function createNewAKG() {
- var waitDialog = SP.UI.ModalDialog.showWaitScreenWithNoClose(SP.Res.dialogLoading15);
- var siteCollUrl = _spPageContextInfo.siteAbsoluteUrl;
- var spHostUrl = encodeURI(siteCollUrl);
- spHostUrl = escapeProperly(spHostUrl);
- var listName = "AKG";
- CreateListItemWithDetails(listName, function (data)
- {
- var url = appSiteCollectionUrl + "/Lists/" + listName + "/EditForm.aspx?ID=" + data.d.ID;
- waitDialog.close(SP.UI.DialogResult.OK);
- openInDialog(1050, 1000, true, true, true, url);
- },
- function (data)
- {
- alert("Ooops, an error occured. Please try again." + data);
- });
- }
- function refresh() {
- $.jgrid.gridUnload('gridmy');
- $.jgrid.gridUnload('gridactive');
- $.jgrid.gridUnload('gridall');
- loadSubTables();
- }
- function showTabsBasedOnGroup() {
- //Admins can see all tabs
- IsCurrentUserMemberOfGroup(groupNameAdmin, function (isCurrentUserInGroup) {
- if (isCurrentUserInGroup) {
- $("#gridadminli").show();
- return;
- } else {
- // $("span:contains('ADM-BM')").parent().hide();
- }
- });
- }
- function printAKG(rowid, divname) {
- var rowData = $("#" + divname).getRowData(rowid);
- var url = _spPageContextInfo.webAbsoluteUrl + "/SitePages/printAKG.html?ID=" + rowData.Id;
- window.open(url, "tabnew" + rowData.Id, "toolbar=yes,titlebar=yes,scrollbars=yes,resizable=yes,width=800,height=600");
- }
- function deleteAKGListItem(itemId) {
- return $.ajax({
- url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('AKG')/items(" + itemId + ")",
- type: 'POST',
- headers: {
- "Accept": "application/json; odata=verbose",
- "X-RequestDigest": $("#__REQUESTDIGEST").val(),
- "IF-MATCH": "*",
- "X-HTTP-Method": "DELETE"
- },
- success: function () {
- },
- error: function (XMLHttpRequest, textStatus, errorThrown) {
- console.log("Status: " + textStatus); alert("Error: " + errorThrown);
- }
- });
- }
- function getAKGListItem(itemId) {
- return $.ajax({
- url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('AKG')/items(" + itemId + ")",
- type: 'GET',
- headers: {
- "Accept": "application/json; odata=verbose",
- },
- success: function (data) {
- return data.d;
- },
- error: function (XMLHttpRequest, textStatus, errorThrown) {
- console.log("Status: " + textStatus); alert("Error: " + errorThrown);
- }
- });
- }
- function deleteAKG(itemId) {
- var waitDialog = SP.UI.ModalDialog.showWaitScreenWithNoClose(SP.Res.dialogLoading15);
- getAKGListItem(itemId).then(function(data) {
- if(data.d.AKGStatus === "Entwurf") {
- var actionItems = [];
- actionItems.push(deleteAKGListItem(itemId));
- actionItems.push(deleteListItemsBatch('Aktionen', itemId));
- actionItems.push(deleteListItemsBatch('Themen', itemId));
- Promise.all(actionItems)
- .then(function() {
- refresh();
- //$("#" + itemId).remove();
- waitDialog.close(SP.UI.DialogResult.OK);
- })
- .catch(function(error) {
- console.log("Error has occured while deleting! ", error);
- waitDialog.close(SP.UI.DialogResult.OK);
- });
- }
- else {
- waitDialog.close(SP.UI.DialogResult.OK);
- alert("Could not delete item: only items with status \"Entwurf\" can be deleted!");
- }
- });
- }
- function writeTabs() {
- var htmlTags = '<div id="tabs">';
- htmlTags += '<ul>';
- htmlTags += '<li><a href="#tabs-1">Meine AKG<span id="gridmyno">[]</span></a></li>';
- htmlTags += '<li><a href="#tabs-2">Aktive AKG<span id="gridactiveno">[]</span></a></li>';
- htmlTags += '<li><a href="#tabs-3">Alle AKG<span id="gridallno">[]</span></a></li>';
- htmlTags += '<li style="display:none;" id="gridadminli"><a title="Dieses Tab ist nur sichtbar fuer ' + groupNameAdmin + '" href="#tabs-4">ADMIN ' + imglock_open + '</a></li>';
- htmlTags += '</ul>';
- htmlTags += '<div id="tabs-1">';
- htmlTags += '<table id="gridmy"></table><div id="pager"> </div>';
- htmlTags += '</div>';
- htmlTags += '<div id="tabs-2">';
- htmlTags += '<table id="gridactive"></table>';
- htmlTags += '</div>';
- htmlTags += '<div id="tabs-3">';
- htmlTags += '<table id="gridall"></table>';
- htmlTags += '</div>';
- htmlTags += '<div id="tabs-4">';
- htmlTags += 'Admin';
- htmlTags += '<a href="/tools/AKG/Lists/Konfiguration/AllItems.aspx" target="_konfig">Konfiguration</a></br>';
- htmlTags += '<a href="/tools/AKG/Lists/Themen/AllItems.aspx" target="_themen">Themen</a></br>';
- htmlTags += '<a href="/tools/AKG/Lists/Aktionen/AllItems.aspx" target="_aktionen">Aktionen</a></br>';
- htmlTags += '</div>';
- htmlTags += '</div>';
- $("#startTabs").html(htmlTags);
- $("#tabs").tabs();
- loadSubTables();
- }
- function loadSubTables() {
- if (checkNull(curuserid) == "") {
- curuserid = _spPageContextInfo.userId;
- }
- loadGrid("AKG", "&$select=Id,Title,Projektstichwort,SD_x002d_Nummer,AKGStatus,Created,Author/Title,Author/Department,Author/WorkPhone&$expand=Author&$filter=" +
- "Author eq " + curuserid +
- " or Projektleiter/Id eq " + curuserid +
- " or Disponent/Id eq " + curuserid +
- " or QM/Id eq " + curuserid +
- " or Vertrieb/Id eq " + curuserid +
- " or AV/Id eq " + curuserid +
- " or Einkauf/Id eq " + curuserid +
- " or Entwicklung/Id eq " + curuserid +
- " or Service/Id eq " + curuserid +
- " or ILS/Id eq " + curuserid +
- " or Operations/Id eq " + curuserid +
- " or PM/Id eq " + curuserid +
- " or Controlling/Id eq " + curuserid +
- " or OMWPQ/Id eq " + curuserid +
- " or Preispr_x00fc_fung/Id eq " + curuserid +
- " or Vertragsstrafe/Id eq " + curuserid +
- " or KompensationOderOffset/Id eq " + curuserid +
- " or Zusatz/Id eq " + curuserid +
- "&$orderby=Id desc", "gridmy", cnMyEntries, cmMyEntries, true, false);
- loadGrid("AKG", "&$select=Id,Title,Projektstichwort,SD_x002d_Nummer,AKGStatus,Created,Author/Title,Author/Department,Author/WorkPhone&$expand=Author&$filter=AKGStatus eq 'Aktiv'&$orderby=Id desc&$top=9999", "gridactive", cnMyEntries, cmMyEntries, true, false);
- loadGrid("AKG", "&$select=Id,Title,archivFlag,Projektstichwort,SD_x002d_Nummer,AKGStatus,Created,Author/Title,Author/Department,Author/WorkPhone&$expand=Author&$orderby=Id desc&$top=9999", "gridall", cnAllEntries, cmAllEntries, true, false);
- }
- function loadGridData(listname, query, divname) {
- $.ajax({
- url: "/tools/AKG/_api/web/lists/getbytitle('" + listname + "')/Items?" + query,
- type: "GET",
- headers: { "Accept": "application/json;odata=verbose" },
- success: function (data, textStatus, xhr) {
- var thegrid = $("#" + divname)[0];
- thegrid.addJSONData(data.d.results); //Binding data to the grid
- },
- error: function (xhr, textStatus, errorThrown) {
- alert("error:" + JSON.stringify(xhr));
- $('#' + divname + 'records').html(" [0]");
- }
- });
- }
- function loadGrid(listname, query, divname, colnames, colmdodel, showFilter, showExcelExport) {
- $("#" + divname).jqGrid({
- datatype: function () { loadGridData(listname, query, divname); },
- colNames: colnames,
- colModel: colmdodel,
- height: "100%",
- loadonce: true,
- rowNum: 9999,
- gridComplete: function () {
- $("#" + divname + "no").html(" [" + $("#" + divname).jqGrid('getGridParam', 'records') + "]");
- $("#" + divname).jqGrid('setGridParam', { datatype: 'local' });
- },
- ondblClickRow: function (rowid, iRow, iCol, e) {
- onDoubleClickGrid(rowid, iRow, iCol, e, divname, listname);
- }
- });
- if (showFilter) {
- $("#" + divname).jqGrid('filterToolbar', {
- autosearch: true,
- stringResult: false,
- searchOnEnter: true,
- defaultSearch: "cn",
- });
- }
- }
- function onDoubleClickGrid(rowid, iRow, iCol, e, divname, listname) {
- var rowData = $("#" + divname).getRowData(rowid);
- var url = appSiteCollectionUrl + "/Lists/" + listname + "/EditForm.aspx?ID=" + rowData.Id;
- openInDialog(1050, 1000, true, true, true, url);
- }
- function onViewClick(rowid, iRow, iCol, e, divname, listname) {
- var rowData = $("#" + divname).getRowData(rowid);
- var url = appSiteCollectionUrl + "/Lists/" + listname + "/DispForm.aspx?ID=" + rowData.Id;
- openInDialog(1050, 1000, true, true, true, url);
- }
- function archiveEntry(akgid, gridid) {
- if (!confirm("Die Themen im ausgewaehlten AKG werden archiviert und sind danach nicht mehr bearbeitbar. Dieser Vorgang kann nicht rueckgaengig gemacht werden. Fortfahren?")) {
- return;
- }
- $("#" + gridid).jqGrid("setCell", akgid, "archivFlag", "startarchiving");
- var table = "<table><tr><td width='20px'> </td><td width='200px'>Thema?<div class='cssHelpTextHeader'>Aktion/Detaillierung/Kurzinformation</div></td><td width='100px'>Verbindl. Zuständigkeit</td><td width='90px'>Termin</td><td width='90px'>Neuer Termin</td><td width='130px' >Status</td><td>Bemerkung</td></tr>";
- var query = "&$filter=refID eq " + akgid + "&$orderby=Sort";
- var tableEncoded = "";
- $.ajax({
- url: "/tools/AKG/_api/web/lists/getbytitle('Themen')/Items?" + query,
- type: "GET",
- headers: { "Accept": "application/json;odata=verbose" },
- success: function (data, textStatus, xhr) {
- var camlQuery = "<Batch OnError='Continue'>"
- for (var i = 0; i < data.d.results.length; i++) {
- curId = data.d.results[i].Id;
- table += "<tr><td>" + data.d.results[i].Sort + "</td>";
- table += "<td>" + data.d.results[i].Title + "<div class='cssHelpText'>" + checkNull(data.d.results[i].Kurzinfo) + "</div></td>";
- table += "<td>" + checkNull(data.d.results[i].Zustandig) + "</td>";
- table += "<td>" + checkNull(data.d.results[i].Termin) + "</td>";
- table += "<td>" + checkNull(data.d.results[i].TerminNeu) + "</td>";
- table += "<td>" + checkNull(data.d.results[i].Status) + "</td>";
- table += "<td>" + checkNull(data.d.results[i].Bemerkung) + "</td>";
- camlQuery += "<Method ID='" + (i + 1) + "' Cmd='Delete'>";
- camlQuery += "<Field Name='ID'>" + data.d.results[i].Id + "</Field>";
- camlQuery += "</Method>";
- table += "</tr>";
- }
- table += "</table>";
- camlQuery += "</Batch>";
- tableEncoded = encodeURIComponent(table);
- // update the item
- var MyvaluePairs = [];
- MyvaluePairs.push(["archivThemen", tableEncoded]);
- MyvaluePairs.push(["archivFlag", "1"]);
- //verschiebt die themen in ein feld innerhalb des akg
- var resultArchiving = archiveAKGThemen(akgid, MyvaluePairs);
- //wenn erfolgreich dann werden die einzelnen themeneintr�ge gel�scht
- if (resultArchiving.status == 200) {
- var resultDeleting = deleteArchivedEntries(camlQuery);
- if (resultDeleting.status == 200) {
- $("#" + gridid).jqGrid("setCell", akgid, "archivFlag", "archivingsuccessful");
- } else {
- //Fehler beim L�schen der Themen
- $("#" + gridid).jqGrid("setCell", akgid, "archivFlag", "archivingfailed");
- alert("Fehler: " + resultDeleting.status + " - " + resultDeleting.statusText + "\n\n" + resultDeleting.responseText);
- }
- } else {
- //Fehler beim Archivieren der Themen
- $("#" + gridid).jqGrid("setCell", akgid, "archivFlag", "archivingfailed");
- alert("Fehler: " + resultArchiving.status + " - " + resultArchiving.statusText + "\n\n" + resultArchiving.responseText);
- }
- },
- error: function (xhr, textStatus, errorThrown) {
- alert("error:" + JSON.stringify(xhr));
- }
- });
- }
- function deleteArchivedEntries(camlQuery) {
- var objPromise = $().SPServices({
- operation: "UpdateListItems",
- async: false,
- listName: "Themen",
- updates: camlQuery,
- });
- return objPromise;
- }
- function archiveAKGThemen(akgid, valuepairs) {
- var result = $().SPServices({
- operation: "UpdateListItems",
- listName: "AKG",
- async: false,
- ID: akgid,
- valuepairs: valuepairs
- });
- return result;
- }
- function checkAkgLink() {
- var akgId = GetUrlKeyValue("autolaunch");
- if (!akgId) {
- return;
- }
- var url = _spPageContextInfo.webAbsoluteUrl + "/Lists/AKG/DispForm.aspx?ID=" + akgId + "&IsDlg=1";
- openInDialog(1050, 1000, true, true, true, url);
- }
- var colIdTemplate = { key: true, index: 'Id', width: 50, sorttype: "int", align: 'center', jsonmap: "Id" }
- var colTitleTemplate = { width: 300 };
- var colTitleShortTemplate = { width: 100 };
- var colActionTemplate = {
- width: 60, align: 'center', sortable: false,
- formatter: function (cellvalue, options, rowObject) {
- var outHtml = "<a title='Eintrag oeffnen' href='javascript:onViewClick(" + options.rowId + ",\"\",\"\",\"\", \"" + options.gid + "\", \"AKG\");'>" + imgView + "</a> ";
- outHtml += "<a title='AKG Drucken' href='javascript:printAKG(" + options.rowId + ", \"" + options.gid + "\", \"AKG\");'>" + imgPrinter + "</a>";
- if (rowObject.AKGStatus === "Entwurf") {
- outHtml += "<a title='AKG Löschen' href='javascript:deleteAKG(" + options.rowId + ");'>" + imgDelete2 + "</a>";
- }
- return outHtml;
- }
- };
- var colArchivingTemplate = {
- width: 50, align: 'center', sortable: false,
- formatter: function (cellvalue, options, rowObject) {
- var outHtml = "";
- switch (cellvalue) {
- case "1":
- outHtml = "<span title='Vorgang bereits archiviert'>" + imgArchived + "</span>";
- break;
- case "startarchiving":
- outHtml = "<span title='Starte Archivierung der Themen'>" + imgLoading + "</span>";
- break;
- case "archivingsuccessful":
- outHtml = "<span title='Archivierung erfolgreich'>" + imgCheck2 + "</span>";
- break;
- case "archivingfailed":
- outHtml = "<span title='Bei der Archivierung trat ein Fehler auf. Bitte erneut versuchen.'>" + imgArchivingError + "</span>";
- break;
- default:
- if (rowObject.AKGStatus == "Archiv") {
- outHtml = "<a title='Themen im AKG archivieren' href='javascript:archiveEntry(" + options.rowId + ",\"" + options.gid + "\");'>" + imgToArchiv + "</a> ";
- }
- }
- return outHtml;
- }
- };
- var colDateTemplate = {
- width: 150, align: 'center', formatter: 'date',
- formatoptions: { srcformat: "ISO8601Long", newformat: "d.m.Y H:i" }
- }
- var colUserTemplate = {
- width: 160, align: 'left',
- formatter: function (cellvalue, options, rowObject) {
- return "<span title='" + cellvalue.Title + "\n" + cellvalue.Department + "\n" + cellvalue.WorkPhone + "'>" + imgUser + " " + cellvalue.Title + "</span>";
- }
- }
- var cnMyEntries = ['ID', 'ProjektNr', '', 'Projektstichwort','AKGStatus','SD-Nummer','Erstellt von', 'Erstellt'];
- var cmMyEntries = [
- { name: 'Id', template: colIdTemplate },
- { name: 'Title', template: colTitleShortTemplate },
- { name: 'actions', template: colActionTemplate },
- { name: 'Projektstichwort', template: colTitleTemplate },
- { name: 'AKGStatus', template: colTitleShortTemplate },
- { name: 'SD_x002d_Nummer', template: colTitleShortTemplate },
- { name: 'Author', template: colUserTemplate },
- { name: 'Created', template: colDateTemplate }
- ];
- var cnAllEntries = ['ID', 'ProjektNr', '', 'Projektstichwort', 'AKGStatus', 'SD-Nummer', 'Erstellt von', 'Erstellt','Archivieren'];
- var cmAllEntries = [
- { name: 'Id', template: colIdTemplate },
- { name: 'Title', template: colTitleShortTemplate },
- { name: 'actions', template: colActionTemplate },
- { name: 'Projektstichwort', template: colTitleTemplate },
- { name: 'AKGStatus', template: colTitleShortTemplate },
- { name: 'SD_x002d_Nummer', template: colTitleShortTemplate },
- { name: 'Author', template: colUserTemplate },
- { name: 'Created', template: colDateTemplate },
- { name: 'archivFlag', template: colArchivingTemplate }
- ];
Add Comment
Please, Sign In to add comment