
web.admin.widgets.lmf_ldcache.js Maven / Gradle / Ivy
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Created by . User: Thomas Kurz Date: 18.02.11 Time: 18:46 To change this
* template use File | Settings | File Templates.
*/
(function($) {
var contentBox;
var programs;
var buttonset;
var loadS;
// new program
var name;
var kind;
var prefix;
var endpoint;
var mime;
var expiry;
var samples;
var samp;
var loader;
$.fn.lmf_ldcache = function(options) {
var settings = {
host : 'http://localhost:8080/LMF/'
}
function addProgram() {
if (name.val() == '') {
alert("name may not be empty!");
return;
}
if (prefix.val() == '') {
alert("prefix may not be empty!");
return;
}
/*if (endpoint.val() == '') {
alert("endpoint may not be empty!");
return;
}
if (mime.val() == '') {
alert("mimetype may not be empty!");
return;
}*/
if (expiry.val() == '') {
alert("expiry may not be empty!");
return;
}
var url = settings.host + "cache/endpoint?name=" + encodeURIComponent(name.val()) + '&prefix='
+ encodeURIComponent(prefix.val()) + '&endpoint=' + encodeURIComponent(endpoint.val()) + '&mimetype='
+ encodeURIComponent(mime.val()) + '&kind=' + encodeURIComponent(kind.val()) + '&expiry='
+ encodeURIComponent(expiry.val());
loader.html("Save Values");
// upload
$.ajax({
type : "POST",
url : url,
contentType : "text/plain",
success : function() {
loader.html("");
$.getJSON(settings.host + "cache/endpoint/list", function(data) {
writePrograms(data);
});
alert("success");
},
error : function(jXHR) {
loader.html("");
alert("Error: " + jXHR.responseText);
}
});
}
function removeProgram(b) {
var url = settings.host + "cache/endpoint/" + b.attr('data-id');
$.ajax({
type : "DELETE",
url : url,
success : function() {
$.getJSON(settings.host + "cache/endpoint/list", function(data) {
writePrograms(data);
});
alert("success");
},
error : function(jXHR, textStatus) {
alert("Error: " + jXHR.responseText);
}
});
}
function activateProgram(b, active) {
var enable = active || (b.attr('data-active') !== "true"),
url = settings.host + "cache/endpoint/" + b.attr('data-id') + "/enable?enable=" + enable;
$.ajax({
type : "POST",
url : url,
success : function() {
$.getJSON(settings.host + "cache/endpoint/list", function(data) {
writePrograms(data);
});
},
error : function(jXHR, textStatus) {
alert("Error: " + jXHR.responseText);
}
});
}
function writeSample(data) {
// contains method
var contains = function(array, obj) {
var i = array.length;
while (i--) {
if (array[i] == obj) {
return true;
}
}
return false;
}
var sorted = [];
for (property in data) {
property = property.substring(15);
property = property.substring(0, property.indexOf('.'));
if (!contains(sorted, property)) {
sorted.push(property);
}
}
sorted.sort();
samples = data;
samp = $('').change(function() {
loadSample(this);
});
var d = $("");
loadS.append(d);
d.append('
Load Sample: ');
d.append(samp);
samp.append('');
for (property in sorted) {
samp.append('');
}
}
function loadSample() {
if (samp.val() != '---select---') {
var x = samp.val();
name.val(samples['ldcache.sample.' + x + '.name'].value);
kind.val(samples['ldcache.sample.' + x + '.kind'].value);
prefix.val(samples['ldcache.sample.' + x + '.prefix'].value);
endpoint.val(samples['ldcache.sample.' + x + '.endpoint'].value);
mime.val(samples['ldcache.sample.' + x + '.mimetype'].value);
expiry.val(samples['ldcache.sample.' + x + '.expiry'].value);
} else {
var x = samp.val();
name.val('');
kind.val('');
prefix.val('');
endpoint.val('');
mime.val('');
expiry.val('');
}
}
function writePrograms(ps) {
if (ps.length == 0) {
programs.text("no endpoints defined");
return;
}
var table = $("
");
var tr = $(" ");
tr.append($(" ").html(" "));
tr.append($(" ").text("Name"));
tr.append($(" ").text("Kind"));
tr.append($(" ").text("Prefix"));
tr.append($(" ").text("Endpoint"));
tr.append($(" ").text("Mimetype"));
tr.append($(" ").text("Expiry"));
tr.append($(" ").text("Actions"));
table.append(tr);
function buildIcon(enabled) {
var icon = $("", {'class': "endpoint_status"});
if (enabled) icon.addClass("on");
return icon;
}
function ctToString(obj) {
var ret = "";
for(var i = 0; i < obj.length; i++) {
ret += obj[i].mime;
if(i != obj.length-1) ret += ",";
}
return ret;
}
for ( var i = 0; i < ps.length; i++) {
if(!ps[i].volatile) {
var delBtn = $("").text("delete");
delBtn.attr('data-id', ps[i].id);
delBtn.click(function() {
removeProgram($(this));
});
var modBtn = $("
© 2015 - 2025 Weber Informatics LLC | Privacy Policy