|
71 | 71 | <legend class="menu-settings-group-name howto">Display location</legend> |
72 | 72 | <div class="menu-settings-input checkbox-input" v-for="menuLocation in menuLocations"> |
73 | 73 | <input type="checkbox" :id="`locations-${menuLocation.slug}`" :name="menuLocation.slug" |
74 | | - :value="menuLocation.id" :checked="menuLocation.id === activeMenuId"/> |
| 74 | + :value="menuLocation.id" :checked="menuLocation.id === activeMenuId && activeMenuId !== 0"/> |
75 | 75 | <label :for="`locations-${menuLocation.slug}`">{{menuLocation.label}}</label> |
76 | 76 | <span v-if="menuLocation.id && menuLocation.id !== activeMenuId" |
77 | 77 | class="theme-location-set">(Currently set to: {{getNavMenuNameById(menuLocation.id)}}) |
|
81 | 81 | </div> |
82 | 82 | </div> |
83 | 83 | <div class="vue-menus__main-footer"> |
84 | | - <a href="#" class="delete" @click.prevent="onDeleteMenu">Delete Menu</a> |
| 84 | + <a v-if="activeMenuId" href="#" class="delete" @click.prevent="onDeleteMenu">Delete Menu</a> |
| 85 | + <span v-else></span> |
85 | 86 | <button type="button" class="button button-primary" @click="onSaveMenu">{{saveMenuText}}</button> |
86 | 87 | </div> |
87 | 88 | </div> |
|
245 | 246 | (response) => { |
246 | 247 | this.menus.push( response ); |
247 | 248 | this.menus.sort( sortBy( 'name' ) ); |
| 249 | + this.updateMenuLocations( response.term_id ); |
| 250 | + this.saveMenuSettings( response.term_id ); |
248 | 251 | this.activeMenuId = response.term_id; |
| 252 | + this.setSuccessMessage( `Menu "${response.name}" created!` ); |
249 | 253 | }, |
250 | 254 | (response) => { |
251 | 255 | console.log( response ); |
|
284 | 288 | const index = findIndex( this.menus, {term_id: response.term_id} ); |
285 | 289 | this.menus[index] = response; |
286 | 290 | this.menus.sort( sortBy( 'name' ) ); |
| 291 | + this.updateMenuLocations( response.term_id ); |
| 292 | + this.saveMenuSettings( response.term_id ); |
287 | 293 | this.activeMenuId = response.term_id; |
| 294 | + this.setSuccessMessage( `Menu "${response.name}" saved!` ); |
288 | 295 | }, |
289 | 296 | (response) => { |
290 | 297 | console.log( response ); |
291 | 298 | this.setErrorMessage( 'Sorry, we were unable to save your menu.' ); |
292 | 299 | } |
293 | 300 | ); |
294 | 301 | }, |
295 | | - saveMenuSettings() { |
| 302 | + saveMenuSettings(menuId) { |
296 | 303 | this.fetch( { |
297 | 304 | method: 'POST', |
298 | | - path: `/wp/v2/menus/${this.activeMenuId}/settings`, |
| 305 | + path: `/wp/v2/menus/${menuId}/settings`, |
299 | 306 | data: this.menuSettings |
300 | 307 | } ) |
301 | 308 | .then( |
|
355 | 362 | }, |
356 | 363 | onSaveMenu() { |
357 | 364 | this.activeMenuId ? this.saveMenu() : this.createMenu(); |
358 | | - this.updateMenuLocations(); |
359 | | - this.saveMenuSettings(); |
360 | 365 | }, |
361 | 366 | onRemoveMenuItem(id) { |
362 | 367 | const menuItem = find( this.menuItems, {ID: id} ); |
|
443 | 448 | } ); |
444 | 449 | return item; |
445 | 450 | }, |
446 | | - updateMenuLocations() { |
| 451 | + updateMenuLocations(menuId) { |
447 | 452 | Array.from( this.$el.querySelectorAll( '.menu-settings .menu-theme-locations input[type="checkbox"]' ) ).forEach( (input) => { |
448 | 453 | const slug = input.getAttribute( 'name' ); |
449 | 454 | const id = parseInt( input.getAttribute( 'value' ), 10 ); |
450 | 455 | const checked = input.checked; |
451 | | - if (!checked && id === this.activeMenuId) { |
| 456 | + if (!checked && id === menuId) { |
452 | 457 | this.setMenuLocation( slug, 0 ); |
453 | 458 | } else if (checked) { |
454 | | - this.setMenuLocation( slug, this.activeMenuId ); |
| 459 | + this.setMenuLocation( slug, menuId ); |
455 | 460 | } |
456 | 461 | } ); |
457 | 462 | } |
|
0 commit comments