All Downloads are FREE. Search and download functionalities are using the official Maven repository.

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 = $('");
            kind = $("");
            endpoint = $("");
            mime = $("");
            expiry = $("");

            newprogram.append("NameValue")

            var tr1 = $("");
            tr1.append("Name");
            var td1 = $("").append(name);
            tr1.append(td1);
            newprogram.append(tr1);

            var tr2 = $("");
            tr2.append("Kind / Provider");
            var td2 = $("").append(kind);
            tr2.append(td2);
            newprogram.append(tr2);

            var tr3 = $("");
            tr3.append("Prefix");
            var td3 = $("").append(prefix);
            tr3.append(td3);
            newprogram.append(tr3);

            var tr4 = $("");
            tr4.append("Enpoint");
            var td4 = $("").append(endpoint);
            tr4.append(td4);
            newprogram.append(tr4);

            var tr5 = $("");
            tr5.append("Mimetype");
            var td5 = $("").append(mime);
            tr5.append(td5);
            newprogram.append(tr5);

            var tr6 = $("");
            tr6.append("Expiry Time");
            var td6 = $("").append(expiry);
            tr6.append(td6);
            newprogram.append(tr6);
        }

        return this.each(function() {
            // merge options
            if (options) {
                $.extend(settings, options);
            }
            contentBox = $(this);
            // build skeleton

            writeContent();

            // $.getJSON(settings.host+"import/types",
            // function(data){write(data);});
        });
    };
})(jQuery);




© 2015 - 2025 Weber Informatics LLC | Privacy Policy