summaryrefslogtreecommitdiff
path: root/extensions/TimedMediaHandler/resources/ext.tmh.transcodetable.js
blob: a8c8f98d67e0dd50802bc0b7dd577568b2ae7aca (plain)
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
/**
* Javascript to support transcode table on image page
*/
( function ( mw, $ ) {
	$( document ).ready( function () {
		var errorPopup, $errorLink;

		errorPopup = function () {
			// pop up dialog
			mw.addDialog( {
				'width': '640',
				'height': '480',
				'title': $(this).attr( 'title' ),
				'content': $('<textarea />')
					.css( {
						'width':'99%',
						'height':'99%'
					} )
					.text( $(this).attr('data-error') )
			} )
			.css( 'overflow', 'hidden' );
			return false;
		};

		// Old version. Need to keep for a little while in case of cached pages.
		$( '.mw-filepage-transcodestatus .errorlink' ).click( errorPopup );
		// New version.
		$errorLink = $( '.mw-filepage-transcodestatus .mw-tmh-pseudo-error-link' );
		$errorLink.wrapInner( function () {
			var $this = $( this );
			return $( '<a />' ).attr( {
				href: '#',
				title: $this.text(),
				'data-error': $this.attr( 'data-error' )
			} ).click( errorPopup );
		} );

		// Reset transcode action:
		$( '.mw-filepage-transcodereset a' ).click( function () {
			var tKey = $( this ).attr( 'data-transcodekey' ),
			buttons = {};

			buttons[ mw.msg( 'mwe-ok' ) ] = function () {
				var api,
					_thisDialog = this,
					cancelBtn = {};

				// Only show cancel button while loading:
				cancelBtn[ mw.msg( 'mwe-cancel' ) ] = function () {
					$(this).dialog( 'close' );
				};
				$( _thisDialog ).dialog( 'option', 'buttons', cancelBtn );

				$( this ).loadingSpinner();

				api = new mw.Api();
				api.postWithEditToken( {
					'action' : 'transcodereset',
					'transcodekey' : tKey,
					'title' : mw.config.get('wgPageName')
				} ).done( function () {
					// Refresh the page
					location.reload();
				} ).fail( function ( code, data ) {
					if( data.error && data.error.info ){
						$( _thisDialog ).text( data.error.info );
					} else {
						$( _thisDialog ).text( mw.msg( 'timedmedia-reset-error' ) );
					}
					var okBtn = {};
					okBtn[ mw.msg('mwe-ok') ] = function() { $(this).dialog( 'close' ); };
					$( _thisDialog ).dialog( 'option', 'buttons', okBtn );
				} );
			};
			buttons[ mw.msg( 'mwe-cancel' ) ] = function () {
				$( this ).dialog( 'close' );
			};
			// pop up dialog
			mw.addDialog( {
				'width': '400',
				'height': '200',
				'title': mw.msg( 'timedmedia-reset' ),
				'content': mw.msg( 'timedmedia-reset-confirm' ),
				'buttons': buttons
			} )
			.css( 'overflow', 'hidden' );
			return false;
		});
	});
} )( mediaWiki, jQuery );