Advertisement
Guest User

ShowComment.vue

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