Index: trunk/phase3/js2/mwEmbed/libTimedText/mvTimeTextEdit.js |
— | — | @@ -37,72 +37,97 @@ |
38 | 38 | 'siprop' : 'languages' |
39 | 39 | } |
40 | 40 | }, function( langDataRaw ) { |
41 | | - var langData = {}; |
42 | | - var languageSelect = '<select id="timed_text_language">'; |
| 41 | + var apprefix = wgTitle.split('.'); |
| 42 | + apprefix.pop(); |
| 43 | + apprefix.pop(); |
| 44 | + apprefix = apprefix.join('.'); |
| 45 | + do_api_req({ |
| 46 | + 'data': { |
| 47 | + 'list' : 'allpages', |
| 48 | + 'apprefix' : apprefix |
| 49 | + } |
| 50 | + }, function( subData ) { |
| 51 | + var availableSubtitles = {}; |
| 52 | + for(var i in subData.query.allpages){ |
| 53 | + var subPage = subData.query.allpages[i]; |
| 54 | + var langKey = subPage.title.split('.'); |
| 55 | + var extension = langKey.pop(); |
| 56 | + langKey = langKey.pop(); |
| 57 | + availableSubtitles[langKey] = subPage.title; |
| 58 | + } |
| 59 | + var langData = {}; |
| 60 | + var languageSelect = '<select id="timed_text_language">'; |
43 | 61 | |
44 | | - var lagRaw = langDataRaw.query.languages; |
45 | | - for(var j in lagRaw){ |
46 | | - var code = lagRaw[j].code; |
47 | | - var language = lagRaw[j]['*']; |
48 | | - langData[ code ] = language; |
49 | | - languageSelect += '<option value="'+code+'">'+language+'('+code+')</option>'; |
50 | | - } |
51 | | - languageSelect += '/</select>'; |
52 | | - var cBtn = {}; |
53 | | - cBtn[ gM('mwe-cancel') ] = function(){ |
54 | | - $j(this).dialog('close'); |
55 | | - } |
56 | | - cBtn[ gM('mwe-ok') ] = function(){ |
57 | | - var file = $j('#timed_text_file_upload'); |
58 | | - var langKey = file[0].files[0].name.split('.'); |
59 | | - var extension = langKey.pop(); |
60 | | - langKey = langKey.pop(); |
61 | | - var mimeTypes = { |
62 | | - 'srt': 'text/x-srt', |
63 | | - 'cmml': 'text/cmml' |
| 62 | + var lagRaw = langDataRaw.query.languages; |
| 63 | + for(var j in lagRaw){ |
| 64 | + var code = lagRaw[j].code; |
| 65 | + var language = lagRaw[j]['*']; |
| 66 | + langData[ code ] = language; |
| 67 | + languageSelect += '<option value="'+code+'">'; |
| 68 | + if (availableSubtitles[code]) { |
| 69 | + languageSelect += language+'('+code+') +'; |
| 70 | + } else { |
| 71 | + languageSelect += language+'('+code+') -'; |
| 72 | + } |
| 73 | + languageSelect += '</option>'; |
64 | 74 | } |
65 | | - if( !mimeTypes[ extension ] ){ |
66 | | - js_log('Error: unknown extension:'+ extension); |
| 75 | + languageSelect += '/</select>'; |
| 76 | + var cBtn = {}; |
| 77 | + cBtn[ gM('mwe-cancel') ] = function(){ |
| 78 | + $j(this).dialog('close'); |
67 | 79 | } |
68 | | - //get language from form |
69 | | - langKey = $j('#timed_text_language').val(); |
| 80 | + cBtn[ gM('mwe-ok') ] = function(){ |
| 81 | + var file = $j('#timed_text_file_upload'); |
| 82 | + var langKey = file[0].files[0].name.split('.'); |
| 83 | + var extension = langKey.pop(); |
| 84 | + langKey = langKey.pop(); |
| 85 | + var mimeTypes = { |
| 86 | + 'srt': 'text/x-srt', |
| 87 | + 'cmml': 'text/cmml' |
| 88 | + } |
| 89 | + if( !mimeTypes[ extension ] ){ |
| 90 | + js_log('Error: unknown extension:'+ extension); |
| 91 | + } |
| 92 | + //get language from form |
| 93 | + langKey = $j('#timed_text_language').val(); |
70 | 94 | |
71 | | - if(extension == "srt") { |
72 | | - var srt = getSubtitle(file[0]); |
73 | | - $j(this).html("saving..."); |
74 | | - $j('.ui-dialog-buttonpane').remove(); |
| 95 | + if(extension == "srt") { |
| 96 | + var srt = getSubtitle(file[0]); |
| 97 | + $j(this).html("saving..."); |
| 98 | + $j('.ui-dialog-buttonpane').remove(); |
75 | 99 | |
76 | | - var editToken = $j('input[name=wpEditToken]').val(); |
77 | | - var title = wgTitle.split('.'); |
78 | | - title.pop(); |
79 | | - title.pop(); |
80 | | - title = title.join('.') + '.' + langKey + '.srt'; |
81 | | - do_api_req({ |
82 | | - 'data': { |
83 | | - 'action' : 'edit', |
84 | | - 'title' : title, |
85 | | - 'text' : srt, |
86 | | - 'token': editToken |
87 | | - } |
88 | | - }, function(dialog) { |
89 | | - return function( result ) { |
90 | | - document.location.href = wgArticlePath.replace('/$1', '?title=' + title + '&action=edit'); |
91 | | - $j(dialog).dialog('close'); |
92 | | - }}(this) |
93 | | - ); |
94 | | - } else { |
95 | | - $j(this).html(gM("mwe-error-only-srt")); |
| 100 | + var editToken = $j('input[name=wpEditToken]').val(); |
| 101 | + var title = wgTitle.split('.'); |
| 102 | + title.pop(); |
| 103 | + title.pop(); |
| 104 | + title = title.join('.') + '.' + langKey + '.srt'; |
| 105 | + do_api_req({ |
| 106 | + 'data': { |
| 107 | + 'action' : 'edit', |
| 108 | + 'title' : title, |
| 109 | + 'text' : srt, |
| 110 | + 'token': editToken |
| 111 | + } |
| 112 | + }, function(dialog) { |
| 113 | + return function( result ) { |
| 114 | + document.location.href = wgArticlePath.replace('/$1', '?title=' + title + '&action=edit'); |
| 115 | + $j(dialog).dialog('close'); |
| 116 | + }}(this) |
| 117 | + ); |
| 118 | + } else { |
| 119 | + $j(this).html(gM("mwe-error-only-srt")); |
| 120 | + } |
96 | 121 | } |
97 | | - } |
98 | | - $j.addDialog(gM("mwe-add-subs-file-title"), |
99 | | - '<input type="file" id="timed_text_file_upload"></input><br />' + languageSelect, |
100 | | - cBtn); |
101 | | - $j('#timed_text_file_upload').change(function(ev) { |
102 | | - var langKey = this.files[0].name.split('.'); |
103 | | - var extension = langKey.pop(); |
104 | | - langKey = langKey.pop(); |
105 | | - $j('#timed_text_language').val( langKey ); |
106 | | - }); |
| 122 | + $j.addDialog(gM("mwe-add-subs-file-title"), |
| 123 | + '<input type="file" id="timed_text_file_upload"></input><br />' + languageSelect, |
| 124 | + cBtn); |
| 125 | + $j('#timed_text_file_upload').change(function(ev) { |
| 126 | + var langKey = this.files[0].name.split('.'); |
| 127 | + var extension = langKey.pop(); |
| 128 | + langKey = langKey.pop(); |
| 129 | + $j('#timed_text_language').val( langKey ); |
| 130 | + }); |
| 131 | + }); |
107 | 132 | }); |
108 | 133 | } |
109 | 134 | $j('#toolbar').hide(); |