Advertisement
Guest User

Component B

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