Dateiverwaltung für die WebBox
ulrich
2018-04-03 af99308ac8192fd47be8f6ec030f973a0bf23072
commit | author | age
e4fec9 1
U 2 var modus = 'kacheln';
3 var fm_slideshow = true;
4 var PERS_DIR = "Persoenlich";
5 var PUB_DIR = "Oeffentlich";
6 var BASE_DIR = "$basis";
7 var DATA_DIR = "$daten";
8 var WWW_DIR = "www";
9 var loc;
10 var pfad = PUB_DIR;
11 var ordner;
12
13
14 function fo_init() {
15   $('.sued').hide();
16   loc = window.location.protocol + '//' + window.location.host;
17   ordner = getURLParameter('o');
18   fo_get_list(ordner);
19 }
20
21 function getURLParameter(name) {
22   return decodeURI(
23     (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
24   );
25 }
26
27 // http://localhost:8079/file-cms/svc?c=de.uhilger.filecms.api.FileMgr&f=JSONNICE&m=list&p=
28 // https://uhilger.de/file-cms/pub?c=de.uhilger.filecms.pub.Catalog&m=listOrdered&p=ulrich/bilder/alben/farbe&p=date&p=asc
29 function fo_get_list(relPfad) {
30   $('#ansicht').attr('onclick','').unbind('click');
31   var m = '?c=de.uhilger.filecms.pub.Catalog&m=listOrdered&p=' + relPfad + '&p=date&p=asc';
32   var u = '../pub' + m;
33   fo_get(u, "json", function(resp) {
34     
35     if(resp.List[0].FileRef !== undefined) {
36       var files = new Array();
37       if(resp.List[0].FileRef instanceof Array) {
38         for(var i = 0; i < resp.List[0].FileRef.length; i++) {
39           files.push(new FileRef(resp.List[0].FileRef[i]));
40         }
41       } else {
42         files.push(new FileRef(resp.List[0].FileRef));
43       }
44       var fl = new FileList(files);
45       fo_render_list(fl);
46     } else {
47       $('#dateien').empty();
48     }
49   });
50 }
51
52 function fo_render_list(fl) {
53   if(modus == 'kacheln') {
54     // Kachelansicht
55     var template = $('#tpl-kacheln').html();
56     Mustache.parse(template);   // optional, speeds up future uses
57     $('.datei-zeile').attr('onclick','').unbind('click');
58     $('#dateien').empty();
59     $('#dateien').html(Mustache.render(template, fl));
60     //$('.figure').click(fm_dateiwahl);
61   } else {
62     // Listenansicht
63     var template = $('#tpl-liste').html();
64     Mustache.parse(template);   // optional, speeds up future uses
65     $('.figure').attr('onclick','').unbind('click');
66     $('#dateien').empty();
67     $('#dateien').html(Mustache.render(template, fl));
68     //$('.datei-zeile').click(fm_dateiwahl);
69   }
70 }
71
72
73 function fo_get(u, dtype, scallback) {
74   $.ajax({
75     url: u,
76     type: "GET",
77     dataType: dtype,
78     success: scallback,
79     error: function (xhr, status, errorThrown) {
80       alert("Error: " + errorThrown + " Status: " + status + " URL: " + u);
81     },
82     complete: function (xhr, status) {
83       //console.log( "The request is complete!" );
84     }
85
86   });
87 }
88
89 function fm_get_path(uid) {
90   //console.log('pfad: ' + pfad);
91   var restdir;
92   if(pfad.indexOf(PUB_DIR) > -1) {
93     restdir = pfad.substr(PUB_DIR.length);
94   } else if(pfad.indexOf(PERS_DIR) > -1) {
95     restdir = pfad.substr(PERS_DIR.length);
96   } else if(pfad.indexOf(BASE_DIR) > -1) {
97     restdir = pfad.substr(BASE_DIR.length);
98   } else if(pfad.indexOf(DATA_DIR) > -1) {
99     restdir = pfad.substr(DATA_DIR.length);
100   }
101   if(restdir !== undefined && restdir.startsWith('/')) {
102     restdir = restdir.substr(1);
103     if(restdir.indexOf(WWW_DIR) > -1) {
104       restdir = restdir.replace(WWW_DIR, 'data');
105     }
106   }
107   var pdir = fm_get_base(uid);
108   // console.log('fm_get_path path: ' + pdir + "/" + restdir);
109   if(restdir.length > 1) {
110     return pdir + "/" + restdir + "/" + ordner;
111   } else {
112     return pdir + "/" + ordner;
113   }
114 }
115
116 function fm_get_base(uid) {
117   //console.log('pfad: ' + pfad);
118   var pdir;
119   if(pfad.indexOf(PUB_DIR) > -1) {
120     pdir = '/data/' + uid;
121   } else if(pfad.indexOf(PERS_DIR) > -1) {
122     pdir = '/home/' + uid;
123   } else if(pfad.indexOf(BASE_DIR) > -1) {
124     pdir = '';
125   } else if(pfad.indexOf(DATA_DIR) > -1) {
126     pdir = '';
127   }
128   //console.log('fm_get_base base: ' + pdir + uid);
129   return pdir;
130 }