Wed Nov 02 2016
Copied to clipboard! Copy reply
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
import Vue from 'vue'
import {store} from './store'
import VueResource from 'vue-resource'
import $ from 'jquery'

window.$ = $
window.jQuery = $

Vue.use(VueResource)




/**************** ADDING SET ***************/

new Vue({
  el: '#form-create-set',
  delimiters: ['{', '}'],
  data: store,
  methods: {
    handleSubmit(e) {
      var formData = new FormData()
      formData.append('name', store.create.name)
      formData.append('urls', store.create.urls)
      formData.append('description', store.create.description)
      window.spf.load('http://localhost:8080/api/create-set', {
        method: 'POST',
        postData: formData,
        onDone: (res) => {

          if (res.response && res.response.result) {
            //spf.navigate('/' + res.response.id)
          }
        },
  	    
        onError: function(e) {
          console.log('[ post error ] ', e)
        }
      })
    },
    handleKeyUp(e) {

    	if (store.create.name.length > 5 && store.create.urls.length > 8 && store.create.description.length > 5) {
    		store.create.submitDisabled = false
    	} else {
    		store.create.submitDisabled = true
    	}
    }
  }
})


/**************** VIEWING SET ***************/
new Vue({
  el: '#urls',
  data: '',
  methods: {

    /* Toggles bug form */
    toggleBugForm(e) {

      var $article = $(e.target).parents('article')
      var $form = $article.find('.add-bug')
      var height, zIndex, opacity
      
      opacity = $form.css('opacity')
      if (opacity == 0) {
        height = '+=200px'
        opacity = 1
        zIndex = 1
      } else {
        opacity = 0
        zIndex = -1
        height = '-=200px'
      }

      $form.css({'z-index':zIndex})
      $article.animate({
        height: height
      })
      $form.animate({
        opacity: opacity
      })
    },

    /* Toggles comment form */
    toggleCommentForm(e) {
      console.log('ay')
      $(e.target).parents('section').find('form').slideToggle()
    },

    /* Handles bug/issue submission */
    handleBugSubmit(e) {
      var urlid = $(e.target).data('urlid')
      var description = $(e.target).find('textarea').val().trim()
      
      if (description.length < 5) {
        // TODO show error
      }

      var formData = new FormData()
      formData.append('description', description)
      formData.append('urlid', urlid)
      window.spf.load('http://localhost:8080/api/create-issue', {
        method: 'POST',
        postData: formData,
        onDone: (res) => {
          if (res.response && res.response.result) {
            //spf.navigate('/' + res.response.id)
          }
        },
        
        onError: function(e) {
          console.log('[ post error ] ', e)
        }
      })
    },


    handleCommentSubmit(e) {
      var comment = $(e.target).find('textarea').val()
      var formData = new FormData()
      formData.append('description', description)
      formData.append('urlid', urlid)
      window.spf.load('http://localhost:8080/api/create-issue', {
        method: 'POST',
        postData: formData,
        onDone: (res) => {
          if (res.response && res.response.result) {
            //spf.navigate('/' + res.response.id)
          }
        },
        
        onError: function(e) {
          console.log('[ post error ] ', e)
        }
      })
    }
  }
})