@@ -19,7 +19,23 @@ $(document).ready(function() {
19
19
$ ( '#search' ) . find ( '.glyphicon' ) . blur ( ) ;
20
20
} ) ;
21
21
$ ( '#search' ) . find ( '.glyphicon-pencil' ) . unbind ( 'click' ) . click ( function ( ) {
22
- alert ( 'Coming soon: edit this archive\'s settings' ) ;
22
+ var profiles = ( 'undefined' != typeof ( storage . get ( 'profiles' ) ) ) ? storage . get ( 'profiles' ) : [ ] ;
23
+ for ( var j = 0 ; j < profiles . length ; j ++ ) {
24
+ for ( var k = 0 ; k < profiles [ j ] . archives . length ; k ++ ) {
25
+ if ( JSON . stringify ( archive ) != JSON . stringify ( profiles [ j ] . archives [ k ] ) ) continue ;
26
+ var profile_index = j ;
27
+ var archive_index = k ;
28
+ break ;
29
+ } ;
30
+ } ;
31
+ archive . profile_index = profile_index ;
32
+ archive . archive_index = archive_index ;
33
+ $ ( '#edit_archive' ) . edit_archive ( archive ) ;
34
+ $ ( '#edit_archive' ) . find ( 'form' ) . unbind ( 'submit' ) . submit ( function ( ) {
35
+ var $form = $ ( this ) ;
36
+ $form . closest ( '.modal' ) . edit_archive ( archive , $form ) ;
37
+ return false ;
38
+ } ) ;
23
39
$ ( '#search' ) . find ( '.glyphicon' ) . blur ( ) ;
24
40
} ) ;
25
41
$ ( '#search' ) . find ( '.glyphicon-trash' ) . unbind ( 'click' ) . click ( function ( ) {
@@ -642,7 +658,57 @@ $.fn.add_archive = function($form) {
642
658
}
643
659
$modal . find ( '#parser' ) . empty ( ) . html ( options ) ;
644
660
} ) ;
645
-
661
+ } ) ;
662
+ }
663
+ } ;
664
+
665
+ //The edit archive modal
666
+ $ . fn . edit_archive = function ( existing_values , $form ) {
667
+ if ( 'undefined' != typeof ( $form ) ) {
668
+ if ( 'undefined' == typeof ( ns ) ) ns = $ . initNamespaceStorage ( 'tensor_ns' ) ; // global
669
+ if ( 'undefined' == typeof ( storage ) ) storage = ns . localStorage ; // global
670
+ var categories = $form . find ( '#categories' ) . val ( ) . split ( / [ \s , ] + / ) ;
671
+ // Create the new archive
672
+ var obj = {
673
+ "title" : $form . find ( '#title' ) . val ( ) ,
674
+ "subtitle" : $form . find ( '#subtitle' ) . val ( ) ,
675
+ "parser" :$form . find ( '#parser' ) . val ( ) ,
676
+ "url" : $form . find ( '#url' ) . val ( ) ,
677
+ "categories" : categories
678
+ } ;
679
+ if ( $form . find ( '#thumbnail' ) . val ( ) . length ) obj . thumbnail = $form . find ( '#thumbnail' ) . val ( ) ;
680
+ var profiles = ( 'undefined' != typeof ( storage . get ( 'profiles' ) ) ) ? storage . get ( 'profiles' ) : { } ;
681
+ profiles [ existing_values . profile_index ] . archives [ existing_values . archive_index ] = $ . extend ( { } , obj ) ;
682
+ storage . set ( 'profiles' , profiles ) ;
683
+ $ ( '#archives' ) . list_archives ( storage . get ( 'profiles' ) ) ;
684
+ $ ( '#collections' ) . list_collections ( storage . get ( 'profiles' ) ) ;
685
+ $ ( '#edit_archive' ) . modal ( 'hide' ) ;
686
+ $ ( '#search_close' ) . click ( ) ;
687
+ $ ( '#archives' ) . find ( '.archive' ) . each ( function ( ) {
688
+ var $archive = $ ( this ) ;
689
+ if ( $archive . find ( 'h5' ) . html ( ) == obj . title && $archive . find ( '.desc' ) . children ( 'div:first' ) . html ( ) == obj . subtitle ) {
690
+ $archive . click ( ) ;
691
+ } ;
692
+ } ) ;
693
+ } else {
694
+ if ( 'undefined' == typeof ( ns ) ) ns = $ . initNamespaceStorage ( 'tensor_ns' ) ; // global
695
+ if ( 'undefined' == typeof ( storage ) ) storage = ns . localStorage ; // global
696
+ return this . each ( function ( ) {
697
+ var $modal = $ ( this ) ;
698
+ $modal . modal ( 'show' ) ;
699
+ $modal . find ( '[name="title"]' ) . val ( existing_values . title ) ;
700
+ $modal . find ( '[name="subtitle"]' ) . val ( existing_values . subtitle ) ;
701
+ $modal . find ( '[name="url"]' ) . val ( existing_values . url ) ;
702
+ $modal . find ( '[name="thumbnail"]' ) . val ( existing_values . thumbnail ) ;
703
+ $modal . find ( '[name="categories"]' ) . val ( existing_values . categories . join ( ', ' ) ) ;
704
+ // Parsers
705
+ $ . getJSON ( $ ( 'link#base_url' ) . attr ( 'href' ) + 'wb/parsers' , function ( json ) {
706
+ var options = '' ;
707
+ for ( var j = 0 ; j < json . length ; j ++ ) {
708
+ options += '<option value="' + json [ j ] + '"' + ( ( json [ j ] == existing_values . parser ) ?' selected' :'' ) + '>' + json [ j ] + '</option>' ;
709
+ }
710
+ $modal . find ( '#parser' ) . empty ( ) . html ( options ) ;
711
+ } ) ;
646
712
} ) ;
647
713
}
648
714
} ;
0 commit comments