* missing api_url removes tab from add-media-wizard
[lhc/web/wiklou.git] / js2 / mwEmbed / libAddMedia / seqRemoteSearchDriver.js
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 */
4
5 var seqRemoteSearchDriver = function(iObj){
6 return this.init( iObj )
7 }
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("seqRs refresh chain::" + _this.pSeq.disp_menu_item);
35 //call the parent
36 _this.pSeq.parent_do_refresh_timeline();
37 //add our local bindings if our window is 'active'
38 if(_this.pSeq.disp_menu_item == 'cliplib'){
39 _this.addResultBindings();
40 }
41 }
42 }
43 },
44 resourceEdit:function(){
45 var _this = this;
46
47 },
48 addResultBindings:function(){
49 //set up seq:
50 var _this = this;
51 //setup parent bindings:
52 this.parent_addResultBindings();
53
54 //add an aditional click binding
55 $j('.rsd_res_item').click(function(){
56 js_log('SeqRemoteSearch: rsd_res_item: click (remove sequence_add_target)');
57 _this.sequence_add_target =false;
58 });
59
60 //add an additional drag binding
61 $j( '.rsd_res_item' ).draggable('destroy').draggable({
62 helper:function(){
63 return $j( this ).clone().appendTo('body').css({'z-index':9999}).get(0);
64 },
65 revert:'invalid',
66 start:function(){
67 js_log('start drag');
68 }
69 });
70 $j(".mv_clip_drag").droppable( 'destroy' ).droppable({
71 accept: '.rsd_res_item',
72 over:function(event, ui){
73 js_log("over : mv_clip_drag: " + $j(this).attr('id') );
74 $j(this).css('border-right', 'solid thick red');
75 },
76 out:function(event, ui){
77 $j(this).css('border-right', 'solid thin white');
78 },
79 drop: function(event, ui) {
80 $j(this).css('border-right', 'solid thin white');
81 js_log("Droped: "+ $j(ui.draggable).attr('id') +' on ' + $j(this).attr('id') );
82 _this.sequence_add_target = $j(this).attr('id');
83 //load the orginal draged item
84 var rObj = _this.getResourceFromId( $j(ui.draggable).attr('id') );
85 _this.resourceEdit(rObj, ui.draggable);
86 }
87 });
88
89 },
90 insertResource:function(rObj){
91 var _this = this;
92 js_log("SEQ insert resource after:" + _this.sequence_add_target );
93 if(_this.sequence_add_target ){
94 var tClip = _this.pSeq.getClipFromSeqID( _this.sequence_add_target );
95 var target_order = false;
96 if(tClip)
97 var target_order = tClip.order;
98 }
99 //@@todo show watting of sorts.
100
101 //get target order:
102 var cat = rObj;
103 //check for target insert path
104 this.checkImportResource( rObj, function(){
105
106 var clipConfig = {
107 'type' : rObj.mime,
108 'uri' : _this.cFileNS + ':' + rObj.target_resource_title,
109 'title' : rObj.title
110 };
111 //set via local properites if avaliable
112 clipConfig['src'] = (rObj.local_src) ? rObj.local_src : rObj.src;
113 clipConfig['poster'] = (rObj.local_poster) ? rObj.local_poster : rObj.poster;
114
115 if(rObj.start_time && rObj.end_time){
116 clipConfig['dur'] = npt2seconds( rObj.end_time ) - npt2seconds( rObj.start_time );
117 }else{
118 //provide a default duration
119 clipConfig['dur'] = 4;
120 }
121
122
123 //create the media element (target order+1 (since we insert (after)
124 _this.pSeq.plObj.tryAddMediaObj(clipConfig, target_order+1 );
125 //refresh the timeline:
126 _this.pSeq.do_refresh_timeline();
127 js_log("run close all: ");
128 _this.closeAll();
129 });
130 },
131 getClipEditControlActions:function(){
132 var _this = this;
133 return {
134 'insert_seq':function(rObj){
135 _this.insertResource( rObj )
136 },
137 'cancel':function(rObj){
138 _this.cancelClipEditCB( rObj )
139 }
140 };
141 },
142 resourceEdit:function(rObj, rsdElement){
143 var _this = this;
144 //don't resize to default (full screen behavior)
145 _this.dmodalCss = {};
146 //open up a new target_contaienr:
147 if($j('#seq_resource_import').length == 0)
148 $j('body').append('<div id="seq_resource_import" style="position:relative"></div>');
149
150 $j('#seq_resource_import').dialog('destroy').dialog({
151 bgiframe: true,
152 width:750,
153 height:480,
154 modal: true,
155 buttons: {
156 "Cancel": function() {
157 $j(this).dialog("close");
158 }
159 }
160 });
161 _this.target_container = '#seq_resource_import';
162 //do parent resource edit (with updated target)
163 this.parent_resourceEdit(rObj, rsdElement);
164 },
165 closeAll:function(){
166 js_log( 'should close: seq_resource_import');
167 $j('#seq_resource_import').dialog('close').dialog('destroy').remove();
168 this.parent_closeAll();
169 },
170 getEditToken:function(callback){
171 if(this.pSeq.sequenceEditToken){
172 callback( this.pSeq.sequenceEditToken )
173 }else{
174 this.parent_getEditToken(callback);
175 }
176 },
177 cancelClipEditCB:function(){
178 js_log('seqRSD:cancelClipEditCB');
179 $j('#seq_resource_import').dialog('close').dialog('destroy').remove();
180 }
181 };