Changeset 139

Show
Ignore:
Timestamp:
02/05/08 23:24:24 (1 year ago)
Author:
Stuart Thiel
Message:

-Fixed #120
-Added sprintf method because it's convenient

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • MediAnnotateXPI/trunk/srcExtension/chrome/MediAnnotate/content/overlay.js

    r136 r139  
    33    // initialization code 
    44    this.initialized = true; 
     5    this.timecodeRegexp = new RegExp(/^(\d{2}):(\d{2}):(\d{2}).(\d{2})$/g); //'^(\d{2}):(\d{2}):(\d{2}).(\d{2})$'; 
     6    this.timecodeRegexpEval = '($1 * 1000 * 1000 * 60) + ($2 * 1000 * 60) + ($3 * 1000) + ($4 * 33.3);' 
     7    this.sprintfString = "%02d:%02d:%02d.%02d"; 
    58  }, 
    69 
     
    9093        //update the fields 
    9194        document.getElementById('ma-description').value = this.xmlDoc.evaluate("//description", this.xmlDoc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent; 
    92         document.getElementById('ma-start-time').value = this.xmlDoc.evaluate("//start", this.xmlDoc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent; 
    93         document.getElementById('ma-end-time').value = this.xmlDoc.evaluate("//end", this.xmlDoc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent; 
     95        var start = this.xmlDoc.evaluate("//start", this.xmlDoc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent; 
     96        var end = this.xmlDoc.evaluate("//end", this.xmlDoc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent; 
     97        document.getElementById('ma-start-time').value = sprintf(this.sprintfString, (start/1000/60/60), ((start%(1000*60*60))/1000/60), ((start%(1000*60))/1000), ((start%1000)/33.3)); 
     98        document.getElementById('ma-end-time').value = sprintf(this.sprintfString, (end/1000/60/60), ((end%(1000*60*60))/1000/60), ((end%(1000*60))/1000), ((end%1000)/33.3)); 
     99        //And here we place the actual value in storage for getting back if the change is flubbed. 
     100 
     101        document.getElementById('ma-old-start-time').value = start; 
     102        document.getElementById('ma-old-end-time').value = end; 
    94103        document.getElementById('ma-itemRef').value = item.getID(); 
    95104                 
     
    110119   
    111120  applyChange: function() { 
     121         
     122        var startTime = document.getElementById('ma-start-time').value; 
     123        var endTime = document.getElementById('ma-end-time').value; 
     124        var oldStartValue = document.getElementById('ma-old-start-time').value; 
     125        var oldEndValue = document.getElementById('ma-old-end-time').value; 
     126 
    112127        if(document.getElementById('ma-itemRef').value && !this.isInMidChange) { 
     128                if(!this.timecodeRegexp.test(startTime) || this.timecodeRegexp.test(endTime)) { 
     129                        alert("Your start and end times must follow proper timecode format."); 
     130                        document.getElementById('ma-start-time').value = sprintf(this.sprintfString, (oldStartValue/1000/60/60), ((oldStartValue%(1000*60*60))/1000/60), ((oldStartValue%(1000*60))/1000), ((oldStartValue%1000)/33.3)); 
     131                        document.getElementById('ma-end-time').value = sprintf(this.sprintfString, (oldEndValue/1000/60/60), ((oldEndValue%(1000*60*60))/1000/60), ((oldEndValue%(1000*60))/1000), ((oldEndValue%1000)/33.3)); 
     132                        return; 
     133                } 
     134         
    113135                this.isInMidChange = true; 
     136                 
     137                oldStartValue = eval(startTime.replace(this.timecodeRegexp, this.timecodeRegexpEval)); 
     138                oldEndValue = eval(endTime.replace(this.timecodeRegexp, this.timecodeRegexpEval)); 
     139                document.getElementById('ma-old-start-time').value = oldStartValue; 
     140                document.getElementById('ma-old-end-time').value = oldEndValue; 
     141                 
    114142                var item = Zotero.Items.get(document.getElementById('ma-itemRef').value); 
    115143                var newNote = "<mediannotate><description>" + document.getElementById('ma-description').value  + "</description>\n" + 
    116                   "<start>" + document.getElementById('ma-start-time').value + "</start>\n" + 
    117                   "<end>" + document.getElementById('ma-end-time').value + "</end></mediannotate>"; 
    118                 item.updateNote(newNote); 
    119                 //Sometimes were applying a change because we've switched to another item and the change in item takes effect before 
    120                 //the onchange takes effect. If that item is a Media Annotation, we'll want to switch back to the MAPanel because 
    121                 //updating the note will have reset it to its normal view, annoyingly enough. 
    122                 if(this.isMediaAnnotation) this.showMAPanel(); 
    123                 var title = document.getElementById('ma-start-time').value + " - " + document.getElementById('ma-end-time').value + " " + Zotero.Notes.noteToTitle(document.getElementById('ma-description').value); 
    124                 item.setField(110, title, false); 
    125                 item.save(); 
     144                  "<start>" + Math.round(oldStartValue-0.5) + "</start>\n" + 
     145                  "<end>" + Math.round(oldEndValue-0.5) + "</end></mediannotate>"; 
     146                try { 
     147                        item.updateNote(newNote); 
     148                        //Sometimes were applying a change because we've switched to another item and the change in item takes effect before 
     149                        //the onchange takes effect. If that item is a Media Annotation, we'll want to switch back to the MAPanel because 
     150                        //updating the note will have reset it to its normal view, annoyingly enough. 
     151                        if(this.isMediaAnnotation) this.showMAPanel(); 
     152                        var title = document.getElementById('ma-start-time').value + " - " + document.getElementById('ma-end-time').value + " " + Zotero.Notes.noteToTitle(document.getElementById('ma-description').value); 
     153                        item.setField(110, title, false); 
     154                        item.save();                     
     155                } catch (someProblem) { 
     156                        alert(someProblem); 
     157                } 
     158 
    126159                if(this.isMediaAnnotation) this.showMAPanel(); 
    127160                this.isInMidChange = false; 
  • MediAnnotateXPI/trunk/srcExtension/chrome/MediAnnotate/content/overlay.xul

    r136 r139  
    22<overlay id="mediannotate-overlay-z" 
    33    xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 
     4    <script src="chrome://mediannotate/content/webtoolkit.sprintf.js"/>  
    45    <script src="chrome://mediannotate/content/overlay.js"/> 
    56    <script src="chrome://mediannotate/content/tags.js"/> 
     
    2324                        <button id="ma-view-button" label="View in MediAnnotate" oncommand="mediannotate.workItOut(event)"/> 
    2425                        <hbox id="ma-time-indicators" flex="0"> 
    25                         <textbox id="ma-start-time" rows="1" cols="8" onchange="mediannotate.applyChange()"/> 
    26                         <textbox id="ma-end-time" rows="1" cols="8" onchange="mediannotate.applyChange()"/> 
     26                        <label hidden="true" id="ma-old-start-time"/> 
     27                        <label hidden="true" id="ma-old-end-time"/> 
     28                        <textbox id="ma-start-time" rows="1" cols="8" onchange="mediannotate.applyChange(event)"/> 
     29                        <textbox id="ma-end-time" rows="1" cols="8" onchange="mediannotate.applyChange(event)"/> 
    2730                        </hbox> 
    2831                        <textbox id="ma-description" rows="8" cols="25" flex="1" multiline="true" onchange="mediannotate.applyChange()"/> 
  • MediAnnotateXPI/trunk/srcExtension/install.rdf

    r136 r139  
    55    <em:id>videannotate@htmlweb.com</em:id> 
    66    <em:name>MediAnnotate</em:name> 
    7     <em:version>0.6.7.5</em:version> 
     7    <em:version>0.6.7.6</em:version> 
    88    <em:creator>Stuart Thiel Concordia University University</em:creator> 
    99    <em:developer>Stuart Thiel</em:developer> 
  • MediAnnotateXPI/trunk/update_mediannotate.rdf

    r136 r139  
    88      <RDF:li> 
    99        <RDF:Description> 
    10           <version>0.6.7.5</version> 
     10          <version>0.6.7.6</version> 
    1111          <targetApplication> 
    1212            <RDF:Description>