45 btnCutChapter.css("left",(pos - wBtnCutChapter)); |
44 btnCutChapter.css("left",(pos - wBtnCutChapter)); |
46 }else{ |
45 }else{ |
47 btnCutChapter.css("left",pos); |
46 btnCutChapter.css("left",pos); |
48 } |
47 } |
49 |
48 |
|
49 /* |
50 //chapitre edit |
50 //chapitre edit |
51 var formChapter = $('.form-chapter-edit'), |
51 var formChapter = $('.form-chapter-edit'), |
52 inputBeginChapter = formChapter.find('input[name=begin]'), |
52 inputBeginChapter = formChapter.find('input[name=begin]'), |
53 inputDurationChapter = formChapter.find('input[name=duration]'), |
53 inputDurationChapter = formChapter.find('input[name=duration]'), |
54 inputEndChapter = formChapter.find('input[name=end]'), |
54 inputEndChapter = formChapter.find('input[name=end]'), |
55 viewBeginChapter = formChapter.find('.begin'), |
55 viewBeginChapter = formChapter.find('.begin'), |
56 viewDurationChapter = formChapter.find('.duration'), |
56 viewDurationChapter = formChapter.find('.duration'), |
57 viewEndChapter = formChapter.find('.end'), |
57 viewEndChapter = formChapter.find('.end'), |
58 timeBegin = global.beginCurrentChapter, |
58 timeBegin = 0, |
59 timeEnd = t.milliseconds, |
59 timeEnd = t.milliseconds, |
60 timeDuration = timeEnd - timeBegin; |
60 timeDuration = timeEnd - timeBegin; |
61 |
61 |
62 inputBeginChapter.val(timeBegin); |
62 inputBeginChapter.val(timeBegin); |
63 inputEndChapter.val(timeEnd); |
63 inputEndChapter.val(timeEnd); |
64 inputDurationChapter.val(timeDuration); |
64 inputDurationChapter.val(timeDuration); |
65 viewBeginChapter.html(millisecondsToString(timeBegin)); |
65 viewBeginChapter.html(millisecondsToString(timeBegin)); |
66 viewDurationChapter.html(millisecondsToString(timeDuration)); |
66 viewDurationChapter.html(millisecondsToString(timeDuration)); |
67 viewEndChapter.html(millisecondsToString(timeEnd)); |
67 viewEndChapter.html(millisecondsToString(timeEnd)); |
|
68 */ |
68 });//timeupdate |
69 });//timeupdate |
69 |
70 |
70 });//myProject.onLoad |
71 });//myProject.onLoad |
71 |
72 |
72 |
73 |
155 $(document).on('keyup', '.project-title-editor-input', function() { |
158 $(document).on('keyup', '.project-title-editor-input', function() { |
156 $('.project-title').html($(this).val()); |
159 $('.project-title').html($(this).val()); |
157 }); |
160 }); |
158 |
161 |
159 //--chapter |
162 //--chapter |
160 $('.list-chapter-wrap').on('click', '.edit-chapter', function(e){ |
163 |
161 e.preventDefault(); |
164 //edit |
162 var viewChapter = { |
165 $('.list-chapter-wrap').on('click', '.btn-edit-chapter', function(e){ |
163 titre : 'titre du chapitre', |
166 e.preventDefault(); |
164 tags : 'tag 1, tag 2, tag 3', |
167 var idChapter = $(this).attr('data-chapter-id'); |
165 description : 'lorem ipsum' |
168 loadFormChapter(idChapter); |
|
169 currentChapter = _.find(chapters, function(c){ return c.id == idChapter; }); |
|
170 }); |
|
171 |
|
172 |
|
173 $('.chapter-widget-info').on('keyup', 'input[name=title], textarea', function(e){ |
|
174 var name = $(this).attr('name'), |
|
175 value = $(this).val(); |
|
176 currentChapter[name] = value; |
|
177 if(name == 'title'){ |
|
178 var idChapter = $(this).parents('form').attr('data-chapter-id'); |
|
179 $('.chapter-segments').find('#'+idChapter).text(value); |
|
180 $('#row-list-chapter-'+idChapter).find('td:first').text(value); |
166 } |
181 } |
167 |
182 }); |
|
183 |
|
184 function onTagItChange(e, ui) { |
|
185 var idChapter = $(this).parents('form').attr('data-chapter-id'), |
|
186 value = $('input[name=tags]').val(); |
|
187 currentChapter.tags = value; |
|
188 $('#row-list-chapter-'+idChapter).find('.list-chapter-tags').text(value); |
|
189 } |
|
190 |
|
191 var tagitParam = { |
|
192 afterTagRemoved : onTagItChange, |
|
193 afterTagAdded : onTagItChange |
|
194 } |
|
195 |
|
196 function loadFormChapter(idChapter){ |
|
197 var chapterData = _.find(chapters, function(c){ return c.id == idChapter; }), |
|
198 chapterWrap = $('.chapter-widget-info'); |
|
199 |
|
200 currentChapter = chapterData; |
|
201 |
168 $.get('template.html', function(templates){ |
202 $.get('template.html', function(templates){ |
169 var tpl = $(templates).filter('#tpl-chapter-edit').html(); |
203 var tpl = $(templates).filter('#tpl-chapter-edit').html(); |
170 var tpl = Mustache.render(tpl, viewChapter); |
204 tpl = Mustache.render(tpl, chapterData); |
171 $('.form-chapter-edit').empty().append(tpl); |
205 chapterWrap.empty().append(tpl); |
172 $('.form-chapter-edit').find('.tag-it').tagit(); |
206 chapterWrap.find('.tag-it').tagit(tagitParam); |
173 }); |
207 }); |
174 }); |
208 } |
175 //nouveau chapitre |
209 |
|
210 |
|
211 //supprimer |
|
212 $('.list-chapter-wrap').on('click', '.btn-delete-chapter', function(e){ |
|
213 e.preventDefault(); |
|
214 |
|
215 if(chapters.length == 1){alert('Le projet doit contenir au moins un chapitre.'); return;} |
|
216 var idChapter = $(this).attr('data-chapter-id'), |
|
217 chapter = _.find(chapters, function(c){ return c.id == idChapter; }), |
|
218 indexChapter = _.indexOf(chapters, chapter), |
|
219 chapterModify; |
|
220 if(indexChapter == 0){ |
|
221 chapterModify = chapters[1]; |
|
222 chapterModify.begin = 0; |
|
223 chapterModify.duration = chapterModify.end; |
|
224 }else{ |
|
225 chapterModify = chapters[indexChapter-1]; |
|
226 chapterModify.end = chapter.end; |
|
227 chapterModify.duration = chapterModify.end - chapterModify.begin; |
|
228 } |
|
229 chapters = _(chapters).reject(function(c) { return c.id == idChapter; }); |
|
230 renderChapter(); |
|
231 //si le formulaire est visible |
|
232 if($('#form-chapter-edit-'+idChapter).length){ |
|
233 $('#form-chapter-edit-'+idChapter).remove(); |
|
234 } |
|
235 }); |
|
236 |
|
237 //nouveau chapitre |
176 $('.chapter-widget').on('click', '.btn-cut-chapter', function(e){ |
238 $('.chapter-widget').on('click', '.btn-cut-chapter', function(e){ |
177 e.preventDefault(); |
239 e.preventDefault(); |
178 |
240 |
179 var uniqId = 'id' + (new Date()).getTime(); |
241 var uniqId = 'id' + (new Date()).getTime(); |
180 |
242 |
181 var formChapter = $('.form-chapter-edit'), |
243 var title = 'New', |
182 title = formChapter.find('input[name=title]').val(), |
244 tags = 'tag', |
183 tags = formChapter.find('input[name=tags]').val(), |
245 begin = myMedia.currentTime.milliseconds, |
184 begin = formChapter.find('input[name=begin]').val(), |
246 end = organizeNewChapter(begin), |
185 duration = formChapter.find('input[name=duration]').val(), |
247 duration = end - begin, |
186 end = formChapter.find('input[name=end]').val(), |
248 description = '', |
187 beginString = millisecondsToString(begin), |
|
188 durationString = millisecondsToString(duration), |
|
189 endString = millisecondsToString(end), |
|
190 description = formChapter.find('textarea[name=description]').val(), |
|
191 id = uniqId; |
249 id = uniqId; |
192 |
250 |
193 var dataChapter = { |
251 var dataChapter = { |
194 title : title, |
252 title : title, |
195 tags : tags, |
253 tags : tags, |
196 begin : begin, |
254 begin : begin, |
197 duration : duration, |
255 duration : duration, |
198 end : end, |
256 end : end, |
199 description : description, |
257 description : description, |
200 beginString : beginString, |
258 color : global.colors[chapters.length], |
201 durationString : durationString, |
259 id : uniqId |
202 endString : endString, |
|
203 id : id |
|
204 }; |
260 }; |
205 |
261 |
206 addChapter(dataChapter); |
|
207 }); |
|
208 |
|
209 function addChapter(dataChapter){ |
|
210 chapters.push(dataChapter); |
262 chapters.push(dataChapter); |
211 |
263 renderChapter(); |
212 //vue liste chapitre |
264 loadFormChapter(id); |
213 $.get('template.html', function(templates){ |
265 }); |
214 var tplChapterRow = $(templates).filter('#tpl-chapter-row').html(); |
|
215 tplChapterRow = Mustache.render(tplChapterRow, dataChapter); |
|
216 $('.list-chapter-rows-wrap').append(tplChapterRow); |
|
217 |
|
218 updateChapterSegments(); |
|
219 }); |
|
220 |
|
221 } |
|
222 |
266 |
223 function updateChapterSegments(){ |
267 function organizeNewChapter(beginNew){ |
|
268 |
|
269 var returnEnd; |
|
270 $.each(chapters, function(k, v){ |
|
271 var begin = v.begin, |
|
272 end = v.end; |
|
273 if(beginNew>=begin && beginNew<=end){ |
|
274 v.end = beginNew; |
|
275 v.duration = v.end - v.begin; |
|
276 returnEnd = end; |
|
277 } |
|
278 }); |
|
279 return returnEnd; |
|
280 } |
|
281 |
|
282 function renderChapter(){ |
224 var chapterSegmentWrap = $('.chapter-segments'), |
283 var chapterSegmentWrap = $('.chapter-segments'), |
225 wChapterSegmentWrap = chapterSegmentWrap.width(); |
284 wChapterSegmentWrap = chapterSegmentWrap.width(), |
|
285 chapterList = $('.list-chapter-rows-wrap'); |
|
286 |
|
287 chapters = _.sortBy(chapters, function(c){ |
|
288 return c.begin; |
|
289 }); |
|
290 |
226 chapterSegmentWrap.empty(); |
291 chapterSegmentWrap.empty(); |
|
292 chapterList.empty(); |
227 |
293 |
228 $.each(chapters, function(k, v){ |
294 $.each(chapters, function(k, v){ |
229 var chapter = v, |
295 |
|
296 //segments |
230 color = global.colors[k], |
297 color = global.colors[k], |
231 width = chapter.duration * wChapterSegmentWrap / global.mediaDuration, |
298 width = Math.floor(v.duration * wChapterSegmentWrap / myMedia.duration.milliseconds), |
232 segment = $('<li>'+chapter.title+'</li>').css({ |
299 segment = $('<li>'+v.title+'</li>').css({ |
233 width : width, |
300 width : width, |
234 backgroundColor : color |
301 backgroundColor : v.color |
235 }).attr('id', chapter.id); |
302 }).attr('id', v.id); |
236 chapterSegmentWrap.append(segment) |
303 |
237 }); |
304 chapterSegmentWrap.append(segment); |
238 } |
305 |
239 |
306 //liste |
240 function loadChapters(){ |
307 $.get('template.html', function(templates){ |
241 //nouveau projet, 1 chapitre |
308 |
|
309 v.beginString = millisecondsToString(v.begin); |
|
310 v.durationString = millisecondsToString(v.duration); |
|
311 v.endString = millisecondsToString(v.end); |
|
312 |
|
313 var tplChapterRow = $(templates).filter('#tpl-chapter-row').html(); |
|
314 tplChapterRow = Mustache.render(tplChapterRow, v); |
|
315 chapterList.append(tplChapterRow); |
|
316 |
|
317 }); |
|
318 }); |
|
319 } |
|
320 |
|
321 //init |
|
322 function loadChapters(){//nouveau projet, 1 chapitre |
|
323 |
242 var uniqId = 'id' + (new Date()).getTime(); |
324 var uniqId = 'id' + (new Date()).getTime(); |
243 |
325 |
244 var title = 'chapitre 1', |
326 var title = 'chapitre 1', |
245 tags = 'tag1,tag2', |
327 tags = 'tag1,tag2', |
246 begin = 0, |
328 begin = 0, |
247 duration = myMedia.duration.milliseconds, |
329 duration = myMedia.duration.milliseconds, |
248 end = myMedia.duration.milliseconds, |
330 end = myMedia.duration.milliseconds, |
249 beginString = millisecondsToString(begin), |
|
250 durationString = millisecondsToString(duration), |
|
251 endString = millisecondsToString(end), |
|
252 description = 'description du chapitre 1', |
331 description = 'description du chapitre 1', |
253 id = uniqId; |
332 id = uniqId; |
254 |
333 |
255 var dataChapter = { |
334 var dataChapter = { |
256 title : title, |
335 title : title, |
257 tags : tags, |
336 tags : tags, |
258 begin : begin, |
337 begin : begin, |
259 duration : duration, |
338 duration : duration, |
260 end : end, |
339 end : end, |
261 description : description, |
340 description : description, |
262 beginString : beginString, |
341 color : global.colors[chapters.length], |
263 durationString : durationString, |
|
264 endString : endString, |
|
265 id : id |
342 id : id |
266 }; |
343 }; |
267 |
344 |
268 addChapter(dataChapter); |
345 chapters.push(dataChapter); |
269 } |
346 renderChapter(); |
|
347 } |
|
348 |
|
349 |
|
350 |
|
351 |
270 |
352 |
271 //edit annotation |
353 //edit annotation |
272 $('#list-annotations').on('click', 'a.btn-edit-annotation', function(e){ |
354 $('#list-annotations').on('click', 'a.btn-edit-annotation', function(e){ |
273 e.preventDefault(); |
355 e.preventDefault(); |
274 |
356 |