| 1 |
( function( window, views, $, settings ) { |
| 2 |
|
| 3 |
var happyforms = { |
| 4 |
template: wp.media.template( 'happyforms-shortcode' ), |
| 5 |
|
| 6 |
getTitle: function( id ) { |
| 7 |
var title = 'Form'; |
| 8 |
|
| 9 |
if ( settings.forms[id] ) { |
| 10 |
title += ': ' + settings.forms[id].post_title; |
| 11 |
} |
| 12 |
|
| 13 |
return title; |
| 14 |
}, |
| 15 |
|
| 16 |
getId: function() { |
| 17 |
return this.shortcode.attrs.named.id; |
| 18 |
}, |
| 19 |
|
| 20 |
initialize: function() { |
| 21 |
var id = this.getId(); |
| 22 |
var title = this.getTitle( id ); |
| 23 |
|
| 24 |
this.render( this.template( { |
| 25 |
id: id, |
| 26 |
title: title, |
| 27 |
} ) ); |
| 28 |
}, |
| 29 |
|
| 30 |
edit: function() { |
| 31 |
var id = this.getId(); |
| 32 |
var returnUrl = encodeURIComponent( document.location.href ); |
| 33 |
var link = settings.editLink.replace( 'ID', id ).replace( 'URL', returnUrl ); |
| 34 |
|
| 35 |
document.location.href = link; |
| 36 |
}, |
| 37 |
} |
| 38 |
|
| 39 |
views.register( 'happyforms', _.extend( {}, happyforms ) ); |
| 40 |
views.register( 'form', _.extend( {}, happyforms ) ); |
| 41 |
|
| 42 |
} )( window, window.wp.mce.views, window.jQuery, _happyFormsAdmin ); |
| 43 |
|