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