* Fixed XSS vulnerability introduced by r49833. Only pre-release versions of MediaWik...
[mediawiki.git] / js2 / mwEmbed / libAddMedia / seqRemoteSearchDriver.js
blob944a2549233ac50cde2bb1b06d45cddea3183669
1 /*the sequence remote search driver
2          extends the base remote search driver with sequence specific stuff.             could seperate this out into seperate lib.
3 */
5 var seqRemoteSearchDriver = function(iObj){
6         return this.init( iObj )
8 seqRemoteSearchDriver.prototype = {
9         sequence_add_target:false,
10         init:function( this_seq ){
11                 var _this = this;
12                 js_log("init:seqRemoteSearchDriver");
13                 //setup remote search driver with a seq parent: 
14                 this.pSeq = this_seq;
15                 var iObj = {                    
16                         'target_container'      : '#cliplib_ic',
17                         'local_wiki_api_url': this_seq.getLocalApiUrl(),                                                                                
18                         'instance_name'         : this_seq.instance_name + '.mySearch',         
19                         'default_query'         : this.pSeq.plObj.title                                                 
20                 }               
21                 //inherit the remoteSearchDriver properties:n           
22                 var tmpRSD = new remoteSearchDriver( iObj );
23                 for(var i in tmpRSD){
24                         if(this[i]){
25                                 this['parent_'+i] = tmpRSD[i];
26                         }else{
27                                 this[i] = tmpRSD[i];
28                         }
29                 }
30                 //extend parent_do_refresh_timeline actions:
31                 if(!this.pSeq.parent_do_refresh_timeline){
32                         this.pSeq.parent_do_refresh_timeline = this.pSeq.do_refresh_timeline;
33                         this.pSeq.do_refresh_timeline = function(){
34                                 js_log("seqRemoteSearchDriver::" + _this.pSeq.disp_menu_item);
35                                 //call the parent
36                                 _this.pSeq.parent_do_refresh_timeline();
37                                 //add our local bindings                                
38                                 _this.addResultBindings();                              
39                                 return true;
40                         }
41                 }
42         },      
43         resourceEdit:function(){
44                 var _this = this;       
45                 
46         },      
47         addResultBindings:function(){
48                 //set up seq:           
49                 var _this = this;
50                 //setup parent bindings:
51                 this.parent_addResultBindings();
52                 
53                 //add an aditional click binding
54                 $j('.rsd_res_item').click(function(){
55                         js_log('SeqRemoteSearch: rsd_res_item: click (remove sequence_add_target)');
56                         _this.sequence_add_target =false;
57                 });
58                 
59                 //add an additional drag binding                                        
60                 $j( '.rsd_res_item' ).draggable('destroy').draggable({
61                         helper:function(){
62                                 return $j( this ).clone().appendTo('body').css({'z-index':9999}).get(0);
63                         },              
64                         revert:'invalid',                                               
65                         start:function(){
66                                 js_log('start drag');
67                         }                                                               
68                 });                             
69                 $j(".mv_clip_drag").droppable( 'destroy' ).droppable({
70                         accept: '.rsd_res_item',
71                         over:function(event, ui){
72                                 //js_log("over : mv_clip_drag: " + $j(this).attr('id') );
73                                 $j(this).css('border-right', 'solid thick red');                                
74                         },
75                         out:function(event, ui){
76                                 $j(this).css('border-right', 'solid thin white');                               
77                         },
78                         drop: function(event, ui) {
79                                 $j(this).css('border-right', 'solid thin white');
80                                 js_log("Droped: "+ $j(ui.draggable).attr('id') +' on ' +  $j(this).attr('id') );
81                                 _this.sequence_add_target =  $j(this).attr('id');
82                                 //load the orginal draged item
83                                 var rObj = _this.getResourceFromId( $j(ui.draggable).attr('id') );                                                      
84                                 _this.resourceEdit(rObj, ui.draggable);                         
85                         }
86                 });             
87         
88         },
89         insertResource:function(rObj){
90                 var _this = this;
91                 js_log("SEQ insert resource after:" + _this.sequence_add_target  + ' of type: ' + rObj.mime);
92                 if(_this.sequence_add_target ){
93                         var tClip = _this.pSeq.getClipFromSeqID( _this.sequence_add_target );           
94                         var target_order = false;
95                         if(tClip)
96                                 var target_order = tClip.order;
97                 } 
98                 //@@todo show watting of sorts. 
99                 
100                 //get target order:
101                 var cat = rObj;                 
102                 //check for target insert path
103                 this.checkImportResource( rObj, function(){     
104                                                                                 
105                         var clipConfig = {                                      
106                                 'type'   : rObj.mime,
107                                 'uri'    : _this.cFileNS + ':' + rObj.target_resource_title,                            
108                                 'title'  : rObj.title                                                           
109                         };                                                                                                                              
110                         //set via local properites if avaliable                 
111                         clipConfig['src'] = (rObj.local_src) ? rObj.local_src : rObj.src;
112                         clipConfig['poster'] = ( rObj.local_poster ) ? rObj.local_poster : rObj.poster;
113                         
114                         if(rObj.start_time && rObj.end_time){
115                                 clipConfig['dur'] = npt2seconds( rObj.end_time ) - npt2seconds( rObj.start_time );
116                         }else{
117                                 //provide a default duration if none set 
118                                 clipConfig['dur'] = 4;
119                         }                       
120                         
121                         //create the media element (target order+1 (since we insert (after)             
122                         _this.pSeq.plObj.tryAddMediaObj( clipConfig, (parseInt(target_order) + 1) );                                                                            
123                         //refresh the timeline: 
124                         _this.pSeq.do_refresh_timeline();
125                         js_log("run close all: ");                                              
126                         _this.closeAll();
127                 });
128         },
129         getClipEditControlActions:function(){
130                 var _this = this;       
131                 return {
132                         'insert_seq':function(rObj){
133                                 _this.insertResource( rObj )
134                         },
135                         'cancel':function(rObj){
136                                 _this.cancelClipEditCB( rObj )
137                         }
138                 };
139         },
140         resourceEdit:function(rObj, rsdElement){
141                 var _this = this;
142                 //don't resize to default (full screen behavior) 
143                 _this.dmodalCss = {};
144                 //open up a new target_contaienr: 
145                 if($j('#seq_resource_import').length == 0)
146                         $j('body').append('<div id="seq_resource_import" style="position:relative"></div>');
147                         
148                 $j('#seq_resource_import').dialog('destroy').dialog({
149                         bgiframe: true,
150                         width:750,
151                         height:480,
152                         modal: true,
153                         buttons: { 
154                                 "Cancel": function() { 
155                                                 $j(this).dialog("close"); 
156                                         } 
157                                 }
158                 });
159                 _this.target_container = '#seq_resource_import';                
160                 //do parent resource edit (with updated target)
161                 this.parent_resourceEdit(rObj, rsdElement);                             
162         },
163         closeAll:function(){
164                 js_log( 'should close: seq_resource_import');
165                 $j('#seq_resource_import').dialog('close').dialog('destroy').remove();
166                 this.parent_closeAll();
167         },
168         getEditToken:function(callback){
169                 if(this.pSeq.sequenceEditToken){
170                         callback( this.pSeq.sequenceEditToken )
171                 }else{
172                         this.parent_getEditToken(callback);
173                 }
174         },
175         cancelClipEditCB:function(){
176                 js_log('seqRSD:cancelClipEditCB');
177                 $j('#seq_resource_import').dialog('close').dialog('destroy').remove();                  
178         }