Guest User

Untitled

a guest
Apr 10th, 2020
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <template>
  2.   <div class="container">
  3.     <table class="table table-hover" id="tblScores">
  4.       <tbody>
  5.         <tr>
  6.           <th scope="row">Date</th>
  7.           <td style="text-align: left">{{this.date}}</td>
  8.         </tr>
  9.         <tr>
  10.           <th scope="row">Category</th>
  11.           <td style="text-align: left">{{this.action}}</td>
  12.         </tr>
  13.         <tr>
  14.           <th scope="row">Comment</th>
  15.           <td style="text-align: left">{{this.details}}</td>
  16.         </tr>
  17.       </tbody>
  18.     </table>
  19.  
  20.     <button type="submit" class="btn btn-primary float-right" @click.prevent="$emit('close')">Close</button>
  21.     <button class="btn btn-primary float-sm-right" style="margin-right:10px" @click.prevent="deleteItem()">Delete</button>
  22.     <button class="btn btn-primary float-sm-right" style="margin-right:10px" @click.prevent="editItem()">Edit</button>
  23.     <EditComment CommentRecID="this.CommentRecID" v-if="showEdit"></EditComment>
  24.   </div>
  25. </template>
  26.  
  27. <script>
  28. import * as $ from "jquery";
  29. import EditComment from "./EditComment.vue";
  30.  
  31.  
  32. export default {
  33.   props: ["CommentRecID"],
  34.   data: function() {
  35.     return {
  36.       date: "",
  37.       action: "",
  38.       details: ""
  39.     };
  40.   },
  41.  
  42.   mounted: function() {
  43.     this.showEdit = true;
  44.     this.loadComments();
  45.   },
  46.   components: {
  47.     //appCharacter: Character,
  48.     appAddComment: EditComment
  49.   },
  50.   methods: {
  51.     loadComments: function() {
  52.       var playerID = this.$store.state.selectedPlayer.ID;
  53.       //var baseUrl = "/DEV/BBUlm" + "/_api/web/lists/";
  54.       var baseUrl = this.$store.state.baseUrl;
  55.       var listName = "Comment";
  56.       //var select = "$select=id, Firstname,lastname";
  57.       var filter = "$filter=ID eq '" + this.CommentRecID + "'";
  58.       baseUrl += "GetByTitle('" + listName + "')/items?" + filter; //+ select;
  59.       var $this = this;
  60.  
  61.       console.log("ShowComment this.CommentRecID: " + this.CommentRecID);
  62.       $.ajax({
  63.         url: baseUrl,
  64.         type: "GET",
  65.         headers: {
  66.           Accept: "application/json;odata=verbose"
  67.         },
  68.         async: false,
  69.         success: function(data, textStatus, xhr) {
  70.           $this.commentsData(data.d.results);
  71.         },
  72.         error: function(xhr, textStatus, errorThrown) {
  73.           alert("error:" + JSON.stringify(xhr));
  74.           $("#start" + "records").html(" [0]");
  75.         }
  76.       });
  77.     },
  78.     commentsData: function(data) {
  79.       //this.date = data[0].Date;
  80.       this.date = this.getJSONDateAsString(data[0].Date, "dd.MM.yyyy");
  81.       this.action = data[0].Category;
  82.       this.details = data[0].Comment;
  83.     },
  84.     getJSONDateAsString: function(jsdatevalue, returnFormat) {
  85.       if ((jsdatevalue == "") | (jsdatevalue == null)) {
  86.         return "";
  87.       }
  88.       return new Date(jsdatevalue).toString(returnFormat);
  89.     },
  90.     deleteItem: function() {
  91.       let siteUrl = 'https://thesite.sharepoint.com/sites/Playercard/';
  92.       let clientContext = new SP.ClientContext(siteUrl);
  93.       let oList = clientContext.get_web().get_lists().getByTitle('Comment');
  94.       let oListItem = oList.getItemById(parseInt(this.CommentRecID));
  95.       oListItem.deleteObject();
  96.       clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded1), Function.createDelegate(this, this.onQueryFailed1));
  97.       this.deleteFromHistory();
  98.     },
  99.  
  100.     onQuerySucceeded1: function(){
  101.       console.log('Item deleted: ' + this.CommentRecID);
  102.     },
  103.  
  104.     onQueryFailed1: function(sender, args){
  105.       console.log('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
  106.     },
  107.  
  108.     deleteFromHistory: function(){
  109.       let siteUrl = 'https://thesite.sharepoint.com/sites/Playercard/';
  110.       let clientContext = new SP.ClientContext(siteUrl);
  111.       let oList = clientContext.get_web().get_lists().getByTitle('History');
  112.       var statID = this.CommentRecID;
  113.       // console.log("statID: " + statID);
  114.  
  115.       let camlQuery = new SP.CamlQuery();
  116.       camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name=\'CorrespondingListID\'/>' +
  117.               '<Value Type=\'Text\'>'+statID+'</Value></Eq></Where></Query></View>');
  118.  
  119.       var collListItem = oList.getItems(camlQuery);
  120.       clientContext.load(collListItem);
  121.       console.log("collListItem: " + collListItem);
  122.  
  123.       // First we much execute the query to retrieve the items
  124.       clientContext.executeQueryAsync(()=> {
  125.                 // Now colListItem is a collection, we must iterate through it
  126.                 var listItemEnumerator = collListItem.getEnumerator();
  127.  
  128.                 while (listItemEnumerator.moveNext()) {
  129.                   var item = listItemEnumerator.get_current();
  130.                   // if we try item.deleteObject() the collection will be modified and it will throw an exception
  131.                   oList.getItemById(item.get_id()).deleteObject();
  132.                 }
  133.                 // Finally execute the delete statements
  134.                 clientContext.executeQueryAsync(
  135.                         () => console.log('Item(s) deleted')),
  136.                         () => console.log('Failed to delete item(s)');
  137.               },
  138.               ()=>console.log('Failed to retrieve items'));
  139.       location.reload();
  140.     },
  141.  
  142.     onQuerySucceeded2: function(){
  143.       console.log('History Comment deleted: ' + this.CommentRecID);
  144.  
  145.     },
  146.  
  147.     onQueryFailed2: function(sender, args){
  148.       console.log('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
  149.     },
  150.  
  151.     editItem: function(){
  152.       var playerID = this.$store.state.selectedPlayer.ID;
  153.       this.$modal.show(
  154.               EditComment,
  155.               {
  156.                 text: playerID
  157.               },
  158.               {
  159.                 draggable: true,
  160.                 width: 400,
  161.                 height: 400
  162.               })
  163.     }
  164.   }
  165. };
  166. </script>
  167.  
  168. <style scoped>
  169. .v--modal {
  170.   padding-top: 15px;
  171.   padding-left: 10px;
  172. }
  173. /* #tblScores tr,
  174. #tblScores td,
  175. #tblScores th {
  176.   border: 0 !important;
  177. } */
  178. </style>
Advertisement
Add Comment
Please, Sign In to add comment