| 
      
            Line 0
          
      
      
        Link Here
      
     | 
  
            
               | 
               | 
              1 | 
              <template>  | 
            
            
              | 2 | 
                  <div v-if="!initialized">{{ $__("Loading") }}</div> | 
            
            
              | 3 | 
                  <div v-else>  | 
            
            
              | 4 | 
                      <h1>{{ title }}</h1> | 
            
            
              | 5 | 
                      <form @submit="processSubmit">  | 
            
            
              | 6 | 
                          <fieldset class="rows">  | 
            
            
              | 7 | 
                              <ol>  | 
            
            
              | 8 | 
                                  <li>  | 
            
            
              | 9 | 
                                      <label class="required" for="name">  | 
            
            
              | 10 | 
                                          {{ $__("Name") }}: | 
            
            
              | 11 | 
                                      </label>  | 
            
            
              | 12 | 
                                      <input  | 
            
            
              | 13 | 
                                          id="name"  | 
            
            
              | 14 | 
                                          v-model="row.name"  | 
            
            
              | 15 | 
                                          :placeholder="$__('Name')" | 
            
            
              | 16 | 
                                          required  | 
            
            
              | 17 | 
                                      />  | 
            
            
              | 18 | 
                                      <span class="required">{{ $__("Required") }}</span> | 
            
            
              | 19 | 
                                  </li>  | 
            
            
              | 20 | 
                                  <li>  | 
            
            
              | 21 | 
                                      <label :for="`user_id`" class="required"  | 
            
            
              | 22 | 
                                          >{{ $__("User") }}:</label | 
            
            
              | 23 | 
                                      >  | 
            
            
              | 24 | 
                                      <span class="user">  | 
            
            
              | 25 | 
                                          {{ patron_str }} | 
            
            
              | 26 | 
                                      </span>  | 
            
            
              | 27 | 
                                      (<a  | 
            
            
              | 28 | 
                                          href="#"  | 
            
            
              | 29 | 
                                          @click="selectUser()"  | 
            
            
              | 30 | 
                                          class="btn btn-default"  | 
            
            
              | 31 | 
                                          >{{ $__("Select user") }}</a | 
            
            
              | 32 | 
                                      >)  | 
            
            
              | 33 | 
                                      <span class="required">{{ $__("Required") }}</span> | 
            
            
              | 34 | 
                                  </li>  | 
            
            
              | 35 | 
                                  <input  | 
            
            
              | 36 | 
                                      type="hidden"  | 
            
            
              | 37 | 
                                      name="selected_patron_id"  | 
            
            
              | 38 | 
                                      id="selected_patron_id"  | 
            
            
              | 39 | 
                                  />  | 
            
            
              | 40 | 
                              </ol>  | 
            
            
              | 41 | 
                          </fieldset>  | 
            
            
              | 42 | 
                          <fieldset class="action">  | 
            
            
              | 43 | 
                              <input type="submit" :value="$__('Submit')" /> | 
            
            
              | 44 | 
                              <router-link  | 
            
            
              | 45 | 
                                  to="../record-sources"  | 
            
            
              | 46 | 
                                  role="button"  | 
            
            
              | 47 | 
                                  class="cancel"  | 
            
            
              | 48 | 
                                  >{{ $__("Cancel") }}</router-link | 
            
            
              | 49 | 
                              >  | 
            
            
              | 50 | 
                          </fieldset>  | 
            
            
              | 51 | 
                      </form>  | 
            
            
              | 52 | 
                  </div>  | 
            
            
              | 53 | 
              </template>  | 
            
            
              | 54 | 
               | 
            
            
              | 55 | 
              <script>  | 
            
            
              | 56 | 
              import { inject } from "vue" | 
            
            
              | 57 | 
              import { RecordSourcesClient } from "../../fetch/record-sources" | 
            
            
              | 58 | 
              import { APIClient } from "../../fetch/api-client.js" | 
            
            
              | 59 | 
              let { | 
            
            
              | 60 | 
                  patron: { patrons }, | 
            
            
              | 61 | 
              } = APIClient  | 
            
            
              | 62 | 
               | 
            
            
              | 63 | 
              export default { | 
            
            
              | 64 | 
                  name: "Edit",  | 
            
            
              | 65 | 
                  setup() { | 
            
            
              | 66 | 
                      const { record_source } = new RecordSourcesClient() | 
            
            
              | 67 | 
                      const { setMessage } = inject("mainStore") | 
            
            
              | 68 | 
                      return { | 
            
            
              | 69 | 
                          setMessage,  | 
            
            
              | 70 | 
                          api: record_source,  | 
            
            
              | 71 | 
                      }  | 
            
            
              | 72 | 
                  },  | 
            
            
              | 73 | 
                  data() { | 
            
            
              | 74 | 
                      return { | 
            
            
              | 75 | 
                          row: { | 
            
            
              | 76 | 
                              name: "",  | 
            
            
              | 77 | 
                          },  | 
            
            
              | 78 | 
                          patron_str: "",  | 
            
            
              | 79 | 
                          initialized: false,  | 
            
            
              | 80 | 
                      }  | 
            
            
              | 81 | 
                  },  | 
            
            
              | 82 | 
                  methods: { | 
            
            
              | 83 | 
                      processSubmit(event) { | 
            
            
              | 84 | 
                          event.preventDefault()  | 
            
            
              | 85 | 
                          const _hasValue = value => { | 
            
            
              | 86 | 
                              return value !== undefined && value !== null && value !== ""  | 
            
            
              | 87 | 
                          }  | 
            
            
              | 88 | 
                          if (!_hasValue(this.row.name) || !_hasValue(this.row.patron_id))  | 
            
            
              | 89 | 
                              return false  | 
            
            
              | 90 | 
                          let response  | 
            
            
              | 91 | 
                          if (this.row.record_source_id) { | 
            
            
              | 92 | 
                              const { record_source_id: id, ...row } = this.row | 
            
            
              | 93 | 
                              response = this.api  | 
            
            
              | 94 | 
                                  .update({ id, row }) | 
            
            
              | 95 | 
                                  .then(() => this.$__("Record source updated!")) | 
            
            
              | 96 | 
                          } else { | 
            
            
              | 97 | 
                              response = this.api  | 
            
            
              | 98 | 
                                  .create({ row: this.row }) | 
            
            
              | 99 | 
                                  .then(() => this.$__("Record source created!")) | 
            
            
              | 100 | 
                          }  | 
            
            
              | 101 | 
                          return response.then(responseMessage => { | 
            
            
              | 102 | 
                              this.setMessage(responseMessage)  | 
            
            
              | 103 | 
                              return this.$router.push({ path: "../record-sources" }) | 
            
            
              | 104 | 
                          })  | 
            
            
              | 105 | 
                      },  | 
            
            
              | 106 | 
                      selectUser() { | 
            
            
              | 107 | 
                          let select_user_window = window.open(  | 
            
            
              | 108 | 
                              "/cgi-bin/koha/members/search.pl?columns=cardnumber,name,category,branch,action&selection_type=select",  | 
            
            
              | 109 | 
                              "PatronPopup",  | 
            
            
              | 110 | 
                              "width=740,height=450,location=yes,toolbar=no," +  | 
            
            
              | 111 | 
                                  "scrollbars=yes,resize=yes"  | 
            
            
              | 112 | 
                          )  | 
            
            
              | 113 | 
                          // This is a bit dirty, the "select user" window should be rewritten and be a Vue component  | 
            
            
              | 114 | 
                          // but that's not for now...  | 
            
            
              | 115 | 
                          select_user_window.addEventListener(  | 
            
            
              | 116 | 
                              "beforeunload",  | 
            
            
              | 117 | 
                              this.newUserSelected,  | 
            
            
              | 118 | 
                              false  | 
            
            
              | 119 | 
                          )  | 
            
            
              | 120 | 
                      },  | 
            
            
              | 121 | 
                      newUserSelected() { | 
            
            
              | 122 | 
                          this.row.patron_id =  | 
            
            
              | 123 | 
                              document.getElementById("selected_patron_id").value | 
            
            
              | 124 | 
                          this.getUserData()  | 
            
            
              | 125 | 
                      },  | 
            
            
              | 126 | 
                      getUserData() { | 
            
            
              | 127 | 
                          patrons.get(this.row.patron_id).then(patron => { | 
            
            
              | 128 | 
                              this.patron_str = $patron_to_html(patron)  | 
            
            
              | 129 | 
                          })  | 
            
            
              | 130 | 
                      },  | 
            
            
              | 131 | 
                  },  | 
            
            
              | 132 | 
                  created() { | 
            
            
              | 133 | 
                      const { id } = this.$route.params | 
            
            
              | 134 | 
                      if (id !== undefined) { | 
            
            
              | 135 | 
                          this.api  | 
            
            
              | 136 | 
                              .get({ | 
            
            
              | 137 | 
                                  id,  | 
            
            
              | 138 | 
                              })  | 
            
            
              | 139 | 
                              .then(response => { | 
            
            
              | 140 | 
                                  Object.keys(response).forEach(key => { | 
            
            
              | 141 | 
                                      this.row[key] = response[key]  | 
            
            
              | 142 | 
                                  })  | 
            
            
              | 143 | 
                                  this.getUserData()  | 
            
            
              | 144 | 
                                  this.initialized = true  | 
            
            
              | 145 | 
                              })  | 
            
            
              | 146 | 
                      } else { | 
            
            
              | 147 | 
                          this.initialized = true  | 
            
            
              | 148 | 
                      }  | 
            
            
              | 149 | 
                  },  | 
            
            
              | 150 | 
                  computed: { | 
            
            
              | 151 | 
                      title() { | 
            
            
              | 152 | 
                          if (!this.row || !this.row.record_source_id)  | 
            
            
              | 153 | 
                              return this.$__("Add record source") | 
            
            
              | 154 | 
                          return this.$__("Edit %s").format(this.row.name) | 
            
            
              | 155 | 
                      },  | 
            
            
              | 156 | 
                  },  | 
            
            
              | 157 | 
              }  | 
            
            
              | 158 | 
              </script>  |