From ffa66bdcd21831a1dabbf47871bdf09c1867c155 Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Mon, 16 Sep 2013 15:00:05 +0200 Subject: [PATCH] add teleforma media retrieval js script --- .../static/teleforma/js/teleforma-media.js | 163 ++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 teleforma/static/teleforma/js/teleforma-media.js diff --git a/teleforma/static/teleforma/js/teleforma-media.js b/teleforma/static/teleforma/js/teleforma-media.js new file mode 100644 index 00000000..eeb94514 --- /dev/null +++ b/teleforma/static/teleforma/js/teleforma-media.js @@ -0,0 +1,163 @@ +/* + * Copyright (C) 2007-2013 Parisson SARL + * Copyright (c) 2011 Riccardo Zaccarelli + * + * This file is part of Telecaster. + * + * TimeSide is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * TimeSide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with TimeSide. If not, see . + * + * Authors: Riccardo Zaccarelli + * Olivier Guilyardi + * Guillaume Pellerin + */ + +/** + * Class for telemeta global functions. + * Note that the dollar sign is a reserved keyword in some browsers + * (see http://davidwalsh.name/dollar-functions) + * which might be in conflict with jQuery dollar sign. + */ + + +/***************************************************************************** + * json(param, method, onSuccesFcn(data, textStatus, jqXHR), onErrorFcn(jqXHR, textStatus, errorThrown)) + * global function to senbd/retrieve data with the server + * + * param: the data to be sent or retrieved. + * param will be converted to string, escaping quotes newlines and backslashes if necessary. + * param can be a javascript string, boolean, number, dictionary and array. + * If dictionary or array, it must contain only the above mentioned recognized types. + * So, eg, {[" a string"]} is fine, {[/asd/]} not + * + * method: the json method, eg "telemeta.update_marker". See base.py + * + * onSuccesFcn(data, textStatus, jqXHR) OPTIONAL --IF MISSING, NOTHING HAPPENS -- + * A function to be called if the request succeeds with the same syntax of jQuery's ajax onSuccess function. + * The function gets passed three arguments + * The data returned from the server, formatted according to the dataType parameter; + * a string describing the status; + * and the jqXHR (in jQuery 1.4.x, XMLHttpRequest) object + * + * onErrorFcn(jqXHR, textStatus, errorThrown) OPTIONAL. --IF MISSING, THE DEFAULT ERROR DIALOG IS SHOWN-- + * A function to be called if the request fails with the same syntax of jQuery ajax onError function.. + * The function receives three arguments: + * The jqXHR (in jQuery 1.4.x, XMLHttpRequest) object, + * a string describing the type of error that occurred and + * an optional exception object, if one occurred. + * Possible values for the second argument (besides null) are "timeout", "error", "abort", and "parsererror". + * ****************************************************************************/ + +var json = function(param,url,method,onSuccessFcn,onErrorFcn){ + //this function converts a javascript object to a string + var toString_ = function(string){ + if(typeof string == "string"){ + //escapes newlines quotes and backslashes + string = string.replace(/\\/g,"\\\\") + .replace(/\n/g,"\\n") + .replace(/"/g,"\\\""); + } + var array; //used for arrays and objects (see below) + if(typeof string == "boolean" || typeof string== "number" || typeof string == "string"){ + string = '"'+string+'"'; + }else if(string instanceof Array){ + array = []; + for(var i = 0;i '; + s += '
\n'; + $(section).html(s); + } + _V_.autoSetup(); + }, + function(){ + s = 'NOT connected'; + $('#layout').html(s); + } + ); + +}; + -- 2.39.5