Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Vue.http.headers.common['X-CSRF-TOKEN'] = $("#token").attr("value");
  2. new Vue({
  3.     el: '#manage-vue-staff',
  4.     data: {
  5.         items: [],
  6.         pagination: {
  7.             total: 0,
  8.             per_page: 2,
  9.             from: 1,
  10.             to: 0,
  11.             current_page: 1
  12.         },
  13.         search:'',
  14.         offset: 4,
  15.         formErrors: {},
  16.         formErrorsUpdate: {},
  17.         newItem: {'nama': '', 'pangkat': '', 'gelar': '', 'jabatan': ''},
  18.         fillItem: {'nama': '', 'pangkat': '', 'gelar': '', 'jabatan': '', 'id': ''}
  19.     },
  20.     computed: {
  21.         isActived: function () {
  22.             return this.pagination.current_page;
  23.         },
  24.         pagesNumber: function () {
  25.             if (!this.pagination.to) {
  26.                 return [];
  27.             }
  28.             var from = this.pagination.current_page - this.offset;
  29.             if (from < 1) {
  30.                 from = 1;
  31.             }
  32.             var to = from + (this.offset * 2);
  33.             if (to >= this.pagination.last_page) {
  34.                 to = this.pagination.last_page;
  35.             }
  36.             var pagesArray = [];
  37.             while (from <= to) {
  38.                 pagesArray.push(from);
  39.                 from++;
  40.             }
  41.             return pagesArray;
  42.         }
  43.     },
  44.     ready: function () {
  45.         this.getVueItems(this.pagination.current_page);
  46.     },
  47.     methods: {
  48.         getVueItems: function (page) {
  49.             this.$http.get('/staffitems?page=' + page + '&search=' + this.search).then((response) => {
  50.                 this.$set('items', response.data.data.data);
  51.                 this.$set('pagination', response.data.pagination);
  52.             });
  53.             setTimeout(this.getVueItems, 5000);
  54.         },
  55.         createItem: function () {
  56.             var input = this.newItem;
  57.             this.$http.post('/staffitems', input).then((response) => {
  58.                 this.changePage(this.pagination.current_page);
  59.                 this.newItem = {'nama': '', 'pangkat': '', 'gelar': '', 'jabatan': ''};
  60.                 $("#create-item").modal('hide');
  61.                 toastr.success('Penyidik Sukses Ditambahkan.', 'Success Alert', {timeOut: 5000});
  62.             }, (response) => {
  63.                 this.formErrors = response.data;
  64.             });
  65.         },
  66.         deleteItem: function (item) {
  67.             this.$http.delete('/staffitems/' + item.id).then((response) => {
  68.                 this.changePage(this.pagination.current_page);
  69.                 toastr.success('Penyidik Sukses Dihapus.', 'Success Alert', {timeOut: 5000});
  70.             });
  71.         },
  72.         editItem: function (item) {
  73.             this.fillItem.id = item.id;
  74.             this.fillItem.nama = item.nama;
  75.             this.fillItem.pangkat = item.pangkat;
  76.             this.fillItem.gelar = item.gelar;
  77.             this.fillItem.jabatan = item.jabatan;
  78.             $("#edit-item").modal('show');
  79.         },
  80.         updateItem: function (id) {
  81.             var input = this.fillItem;
  82.             this.$http.put('/staffitems/' + id, input).then((response) => {
  83.                 this.changePage(this.pagination.current_page);
  84.                 this.newItem = {'nama': '', 'pangkat': '', 'gelar': '', 'jabatan': ''};
  85.                 $("#edit-item").modal('hide');
  86.                 toastr.success('Data Penyidik Sukses Dimutakhirkan.', 'Success Alert', {timeOut: 5000});
  87.             }, (response) => {
  88.                 this.formErrors = response.data;
  89.             });
  90.         },
  91.         changePage: function (page) {
  92.             this.pagination.current_page = page;
  93.             this.getVueItems(page);
  94.         }
  95.     }
  96. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement