Changeset 24948


Ignore:
Timestamp:
2012-01-16T15:02:27+13:00 (12 years ago)
Author:
sjm84
Message:

Some initial updates to allow deletion of text annotations

Location:
main/trunk/model-cols-dev/peijones
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/model-cols-dev/peijones/etc/collectionConfig.xml

    r24946 r24948  
    207207        </script>
    208208        <script text="text/javascript">
    209           <xsl:text disable-output-escaping="yes">
     209            <xsl:text disable-output-escaping="yes">
    210210                       
    211211                        var _posCount = 0;
     
    243243                                            }
    244244                                        }
     245                                        _posCount--;
    245246                                    },
    246247                                    failed: function(){alert("Failed to delete index metadata of note with id: " + note.id);},
     
    358359        </script>
    359360        <script text="text/javascript">
    360           <xsl:text disable-output-escaping="yes">
     361            <xsl:text disable-output-escaping="yes">
    361362           
    362363            function checkLoop(pid, serverFunction, callback)
     
    465466            function saveAndBuildCollection(col)
    466467            {           
     468                for(var j = 0; j &lt; gs.toDeleteArray.keys.length; j++)
     469                {
     470                    var current = gs.toDeleteArray[gs.toDeleteArray.keys[j]];
     471                    if(current == null){continue;}
     472                    var metaToDelete = ["user", "text", "tags"];
     473                   
     474                    for(var l = 0; l &lt; metaToDelete.length; l++)
     475                    {
     476                        var deleteArchivesURL = "cgi-bin/metadata-server.pl?\
     477                            a=remove-archives-metadata&amp;\
     478                            c=" + gs.cgiParams.c + "&amp;\
     479                            site=localsite&amp;\
     480                            docid=" + gs.cgiParams.d + "&amp;\
     481                            metaname=gstext." + metaToDelete[l] + "&amp;\
     482                            metavalue=" + ((l == 2) ? (current.user.name) : (current[metaToDelete[l]]));
     483                           
     484                        var deleteIndexURL = "cgi-bin/metadata-server.pl?\
     485                            a=remove-metadata&amp;\
     486                            c=" + gs.cgiParams.c + "&amp;\
     487                            site=localsite&amp;\
     488                            docid=" + gs.cgiParams.d + "&amp;\
     489                            metaname=gstext." + metaToDelete[l] + "&amp;\
     490                            metavalue=" + ((l == 2) ? (current.user.name) : (current[metaToDelete[l]]));
     491                           
     492                        var deleteImportURL = "cgi-bin/metadata-server.pl?\
     493                            a=remove-import-metadata&amp;\
     494                            c=" + gs.cgiParams.c + "&amp;\
     495                            site=localsite&amp;\
     496                            docid=" + gs.cgiParams.d + "&amp;\
     497                            metaname=gstext." + metaToDelete[l] + "&amp;\
     498                            metavalue=" + ((l == 2) ? (current.user.name) : (current[metaToDelete[l]]));
     499                           
     500                        var deleteArchivesCallback =
     501                        {
     502                            success:function(){},
     503                            failed: function(){alert("Failed to save text annotations index metadata");}
     504                        }
     505                        YAHOO.util.Connect.asyncRequest("GET", deleteArchivesURL, deleteArchivesCallback);
     506
     507                        var deleteIndexCallback =
     508                        {
     509                            success:function(){},
     510                            failed: function(){alert("Failed to save text annotations import metadata");}
     511                        }
     512                        YAHOO.util.Connect.asyncRequest("GET", deleteIndexURL, deleteIndexCallback);
     513
     514                        var deleteImportCallback =
     515                        {
     516                            success:function(){},
     517                            failed: function(){alert("Failed to save text annotations import metadata");}
     518                        }
     519                        YAHOO.util.Connect.asyncRequest("GET", deleteImportURL, deleteImportCallback);
     520                    }
     521                }
     522           
    467523                var json = "[";
    468524                for(var i = 0; i &lt; gs.annotationArray.keys.length; i++)
    469525                {
    470526                    var current = gs.annotationArray[gs.annotationArray.keys[i]];
     527                    if(current == null){continue;}                 
    471528                    var metaToAdd = ["user", "text", "tags"];
    472529                   
     
    481538                            json += '{"docid":"' + gs.cgiParams.d + '", "metaname":"gstext.' + metaToAdd[j] + '", "metavalue":"' + current[metaToAdd[j]] + '"}';
    482539                        }
    483                        
     540
    484541                        if(j != (metaToAdd.length - 1) || i != (gs.annotationArray.keys.length - 1))
    485542                        {
     
    489546                }
    490547                json += "]";
    491                
     548
    492549                var saveArchivesURL = "cgi-bin/metadata-server.pl?a=set-archives-metadata-array&amp;c=" + gs.cgiParams.c + "&amp;site=localsite&amp;collect=" + gs.cgiParams.c + "&amp;json=" + json;
    493550                var saveIndexURL = "cgi-bin/metadata-server.pl?a=set-metadata-array&amp;c=" + gs.cgiParams.c + "&amp;site=localsite&amp;collect=" + gs.cgiParams.c + "&amp;json=" + json;
    494                 var saveImportURL = "cgi-bin/metadata-server.pl?a=set-import-metadata-array&amp;c=" + gs.cgiParams.c + "&amp;site=localsite&amp;collect=" + gs.cgiParams.c + "&amp;json=" + json; //FIX THIS
    495                
     551                var saveImportURL = "cgi-bin/metadata-server.pl?a=set-import-metadata-array&amp;c=" + gs.cgiParams.c + "&amp;site=localsite&amp;collect=" + gs.cgiParams.c + "&amp;json=" + json;
     552
    496553                var saveArchivesCallback =
    497554                {
     
    500557                }
    501558                YAHOO.util.Connect.asyncRequest("GET", saveArchivesURL, saveArchivesCallback);
    502                
     559
    503560                var saveIndexCallback =
    504561                {
     
    507564                }
    508565                YAHOO.util.Connect.asyncRequest("GET", saveIndexURL, saveIndexCallback);
    509                
     566
    510567                var saveImportCallback =
    511568                {
     
    516573            }
    517574                   
    518                         function initAnnotator()
    519                         {       
    520                             gs.annotationArray = new Array();
    521                             gs.annotationArray.keys = new Array();
    522                            
    523                             var elem = document.getElementById("gs-document-text");
    524                             elem.innerHTML = '&lt;button id="saveButton"&gt;Save annotations&lt;/button&gt;&lt;br/&gt;' + elem.innerHTML;
    525                            
    526                             var button = document.getElementById("saveButton");
    527                             button.onclick = function(){saveAndBuildCollection(gs.cgiParams.c);};
    528                            
    529                             jQuery(function ($) {
    530                                 if (typeof $.fn.annotator !== 'function') {
    531                                     alert("Ooops! it looks like you haven't built the Annotator concatenation file. " + "Either download a tagged release from GitHub, or modify the Cakefile to point " + "at your copy of the YUI compressor and run `cake package`.");
    532                                 } else {   
    533                                     /*
    534                                     jQuery('#gs-document-text').annotator()
    535                                     .annotator('addPlugin', 'Store', {
    536                                         prefix: 'http://annotateit.org/api',
    537                                         annotationData: {'uri':document.URL}
    538                                     })
    539                                     .annotator('addPlugin', 'Auth', {
    540                                         userId: 'papitha',          // Your AnnotateIt username
    541                                         consumerKey: '39fc339cf058bd22176771b3e33c5dac',           // Your Account Key
    542                                         authToken: '852b7fc25396d2aedf9aeb44dd58518faa679dbf027892164bfb81900bd09741' // Your Auth Token
    543                                     });
    544                                     */ 
    545 
    546                                     jQuery(function ($) {
    547                                         // Include AnnotateIt credentials to load the store plugin.
    548                                         $('#gs-document-text').annotator().annotator('setupPlugins', {
    549                                             userId:    'papitha',
    550                                             userName:  'Papitha',
    551                                             accountId: '39fc339cf058bd22176771b3e33c5dac',
    552                                             authToken: '852b7fc25396d2aedf9aeb44dd58518faa679dbf027892164bfb81900bd09741', 
    553                                         }, {
    554                                             Store:
    555                                             {
    556                                                 prefix: 'http://localhost:5000',
    557                                                 annotationData: {'uri':gs.cgiParams.c + "-" + gs.cgiParams.d},
    558                                                 loadFromSearch: {'uri':gs.cgiParams.c + "-" + gs.cgiParams.d}
    559                                             }
    560                                         });
    561                                     });
     575            function initAnnotator()
     576            {       
     577                gs.annotationArray = new Array();
     578                gs.annotationArray.keys = new Array();
     579               
     580                gs.toDeleteArray = new Array();
     581                gs.toDeleteArray.keys = new Array();
     582               
     583                var elem = document.getElementById("gs-document-text");
     584                elem.innerHTML = '&lt;button id="saveButton"&gt;Save annotations&lt;/button&gt;&lt;br/&gt;' + elem.innerHTML;
     585               
     586                var button = document.getElementById("saveButton");
     587                button.onclick = function(){saveAndBuildCollection(gs.cgiParams.c);};
     588               
     589                jQuery(function ($) {
     590                    if (typeof $.fn.annotator !== 'function') {
     591                        alert("Ooops! it looks like you haven't built the Annotator concatenation file. " + "Either download a tagged release from GitHub, or modify the Cakefile to point " + "at your copy of the YUI compressor and run `cake package`.");
     592                    } else {
     593                        jQuery(function ($) {
     594                            // Include AnnotateIt credentials to load the store plugin.
     595                            $('#gs-document-text').annotator().annotator('setupPlugins', {
     596                                userId:    'papitha',
     597                                userName:  'Papitha',
     598                                accountId: '39fc339cf058bd22176771b3e33c5dac',
     599                                authToken: '852b7fc25396d2aedf9aeb44dd58518faa679dbf027892164bfb81900bd09741', 
     600                            }, {
     601                                Store:
     602                                {
     603                                    prefix: 'http://localhost:5000',
     604                                    annotationData: {'uri':gs.cgiParams.c + "-" + gs.cgiParams.d},
     605                                    loadFromSearch: {'uri':gs.cgiParams.c + "-" + gs.cgiParams.d}
    562606                                }
    563607                            });
    564                         }
    565                     </xsl:text>
     608                        });
     609                    }
     610                });
     611            }
     612        </xsl:text>
    566613        </script>
    567614      </xsl:template>
  • main/trunk/model-cols-dev/peijones/js/annotator/pkg/annotator-full.min.js

    r24947 r24948  
    659659            var w, v, y, x;
    660660            x = u.highlights;
     661           
    661662            for (v = 0, y = x.length; v < y; v++) {
    662663                w = x[v];
    663664                h(w).replaceWith(w.childNodes)
    664665            }
     666           
     667            var rangeString = u.ranges[0].startOffset + "_" + u.ranges[0].endOffset;
     668            gs.toDeleteArray[rangeString] = gs.annotationArray[rangeString];
     669            gs.toDeleteArray.keys.push(rangeString);
     670            gs.annotationArray[rangeString] = null;
     671           
    665672            this.publish("annotationDeleted", [u]);
    666673            return u
Note: See TracChangeset for help on using the changeset viewer.