| 1 |
import StockpackTimer from './utils/stockpack-timer'; |
| 2 |
|
| 3 |
const StockpackEmpty = wp.media.View.extend( /** @lends wp.media.view.Toolbar.prototype */{ |
| 4 |
tagName: 'div', |
| 5 |
className: 'stockpack-empty', |
| 6 |
template: wp.template( 'stockpack-empty' ), |
| 7 |
|
| 8 |
events: { |
| 9 |
'click .retry': 'retry', |
| 10 |
}, |
| 11 |
|
| 12 |
defaults: { |
| 13 |
message: '', |
| 14 |
link: false, |
| 15 |
retry: true, |
| 16 |
}, |
| 17 |
|
| 18 |
timer: null, |
| 19 |
|
| 20 |
initialize() { |
| 21 |
this.model = new Backbone.Model( this.defaults ); |
| 22 |
// If any of the `options` have a key from `defaults`, apply its |
| 23 |
// value to the `model` and remove it from the `options object. |
| 24 |
_.each( this.defaults, function( def, key ) { |
| 25 |
const value = this.options[ key ]; |
| 26 |
if ( _.isUndefined( value ) ) { |
| 27 |
return; |
| 28 |
} |
| 29 |
|
| 30 |
this.model.set( key, value ); |
| 31 |
delete this.options[ key ]; |
| 32 |
}, this ); |
| 33 |
this.listenTo( this.model, 'change', this.render ); |
| 34 |
|
| 35 |
this.controller.on( 'start-retry', _.bind( this.retry, this ) ); |
| 36 |
}, |
| 37 |
|
| 38 |
render() { |
| 39 |
wp.Backbone.View.prototype.render.apply( this, arguments ); |
| 40 |
this.afterRender(); |
| 41 |
return this; |
| 42 |
}, |
| 43 |
|
| 44 |
afterRender() { |
| 45 |
this.maybeCreateTimer(); |
| 46 |
}, |
| 47 |
|
| 48 |
dispose() { |
| 49 |
this.$el.remove(); |
| 50 |
if ( this.timer ) { |
| 51 |
this.timer.destroy(); |
| 52 |
} |
| 53 |
}, |
| 54 |
|
| 55 |
prepare() { |
| 56 |
return this.model.toJSON(); |
| 57 |
}, |
| 58 |
|
| 59 |
maybeCreateTimer() { |
| 60 |
if ( this.$el.find( '.stockpack-timer' ).length ) { |
| 61 |
this.timer = new StockpackTimer( this.$el.find( '.stockpack-timer' ) ); |
| 62 |
} |
| 63 |
}, |
| 64 |
|
| 65 |
retry() { |
| 66 |
this.options.browser.updateContent(); |
| 67 |
}, |
| 68 |
|
| 69 |
show() { |
| 70 |
this.$el.removeClass( 'hidden' ); |
| 71 |
}, |
| 72 |
hide() { |
| 73 |
this.$el.addClass( 'hidden' ); |
| 74 |
}, |
| 75 |
|
| 76 |
} ); |
| 77 |
|
| 78 |
export default StockpackEmpty; |
| 79 |
|