From: riccardo Date: Mon, 7 Feb 2011 15:54:58 +0000 (+0100) Subject: send marker request works X-Git-Tag: 1.1~466 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=b170432188b26fe8e723f009b041dde84a18f09e;p=telemeta.git send marker request works --- diff --git a/telemeta/htdocs/timeside/src/controller.js b/telemeta/htdocs/timeside/src/controller.js index e8e41dd5..0ed4989f 100644 --- a/telemeta/htdocs/timeside/src/controller.js +++ b/telemeta/htdocs/timeside/src/controller.js @@ -164,52 +164,42 @@ TimeSide(function($N) { }, sendHTTP: function(marker){ - var data2send = {"item_id": itemid, "public_id": marker.id, "time": marker.offset, - "description": marker.desc}; - + //itemid is the item (spund file) name var sPath = window.location.pathname; //remove last "/" or last "/#", if any... sPath = sPath.replace(/\/#*$/,""); var itemid = sPath.substring(sPath.lastIndexOf('/') + 1); + //WARNING: use single quotes for the whole string!! + //see http://stackoverflow.com/questions/4809157/i-need-to-pass-a-json-object-to-a-javascript-ajax-method-for-a-wcf-call-how-can + var data2send = '{"id":"jsonrpc", "params":[{"item_id":"'+ itemid+'", "public_id": "'+marker.id+'", "time": "'+ + marker.offset+'","description": "'+marker.desc+'"}], "method":"telemeta.add_marker","jsonrpc":"1.0"}'; + - //don't change the order BELOW unless the relative python code for the server changes as - //well: - //var data2send = [itemid, marker.id, marker.offset, marker.desc]; $.ajax({ type: "POST", - url: "/json", - method: "telemeta.add_marker", - data: data2send, - dataType: 'text', - contentType: 'application/json; charset=utf-8', -// success: function(msg){ -// alert( "Data Saved: " + msg ); -// }, - error: function(msg){ - alert("Error: "+msg); - - } - + url: 'http://localhost:9000/json/', + contentType: "application/json", + data: data2send }); }, quote: function(string){ -// var s = "\""; -// var isEscaped = false; -// for(var i=0; i'); - this.forwardEvent = this.attach(this._forwardEvent); - }, - - free: function() { - this.eventContainer = null; - }, - - configure: function(config, defaults) { - if (!config) - config = {}; - for (k in defaults) { - var value = null, flags = []; - - if (defaults[k] && typeof defaults[k][0] !== 'undefined') { - value = defaults[k][0]; - if (defaults[k][1]) { - flags = defaults[k][1].split(","); - } - } else { - value = defaults[k]; + $N.Core = $N.Class.create("Core", { + eventContainer: null, + eventPrefix: '', + cfg: {}, + + initialize: function() { + this.debug("new instance"); + $N.registerInstance(this); + this.eventContainer = $J('
'); + this.forwardEvent = this.attach(this._forwardEvent); + }, + + free: function() { + this.eventContainer = null; + }, + + configure: function(config, defaults) { + if (!config){ + config = {}; + } + for (k in defaults) { + var value = null, flags = []; - if (typeof config[k] !== 'undefined') - value = config[k]; + if (defaults[k] && typeof defaults[k][0] !== 'undefined') { + value = defaults[k][0]; + if (defaults[k][1]) { + flags = defaults[k][1].split(","); + } + } else { + value = defaults[k]; + } - var source = this; - $J(flags).each(function(i, flag) { - switch (flag) { - case 'required': - if (value === null) - throw new $N.RequiredOptionError(source, k); - break; - /* + if (typeof config[k] !== 'undefined'){ + value = config[k]; + } + + var source = this; + $J(flags).each(function(i, flag) { + switch (flag) { + case 'required': + if (value === null) + throw new $N.RequiredOptionError(source, k); + break; + /* case 'element': value = $J(value); break; */ - } - }); + } + }); - this.cfg[k] = value; - } - return this; - }, - - observe: function(eventName, handler) { - this.eventContainer.bind(this.eventPrefix + eventName, handler); - return this; - }, - - fire: function(eventName, data) { - if (!data) - data = {}; - this.eventContainer.trigger(this.eventPrefix + eventName, data); - return this; - }, - - _forwardEvent: function(e, data) { - if (!data) - data = {}; - this.eventContainer.trigger(e.type, data); - return this; - }, - - _textWidth: function(text, fontSize) { - var ratio = 3/5; - return text.length * ratio * fontSize; - }, - - debug: function(message) { - if ($N.debugging && typeof console != 'undefined' && console.log) { - console.log('TimeSide.' + this.__class__.__name__ + ': ' + message); - } - }, + this.cfg[k] = value; + } + return this; + }, - attach: function(method) { - return $N.attachFunction(this, method); - }, + observe: function(eventName, handler) { + this.eventContainer.bind(this.eventPrefix + eventName, handler); + return this; + }, - attachWithEvent: function(method) { - return $N.attachAsEventListener(this, method); - }, + fire: function(eventName, data) { + if (!data){ + data = {}; - uniqid: function() { - d = new Date(); - return new String(d.getTime() + '' + Math.floor(Math.random() * 1000000)).substr(0, 18); - } -}); + } + this.eventContainer.trigger(this.eventPrefix + eventName, data); + return this; + }, -$N.Class.create("Exception", { - _source: null, - _message: null, + _forwardEvent: function(e, data) { + if (!data){ + data = {}; + + } + this.eventContainer.trigger(e.type, data); + return this; + }, - initialize: function(source, message) { - this._source = source; - this._message = message; - }, - toString: function() { - return this.__class__.__name__ + " from TimeSide." + this._source.__class__.__name__ + _textWidth: function(text, fontSize) { + var ratio = 3/5; + return text.length * ratio * fontSize; + }, + + debug: function(message) { + if ($N.debugging && typeof console != 'undefined' && console.log) { + console.log('TimeSide.' + this.__class__.__name__ + ': ' + message); + } + }, + + attach: function(method) { + return $N.attachFunction(this, method); + }, + + attachWithEvent: function(method) { + return $N.attachAsEventListener(this, method); + }, + + uniqid: function() { + d = new Date(); + return new String(d.getTime() + '' + Math.floor(Math.random() * 1000000)).substr(0, 18); + } + }); + + $N.Class.create("Exception", { + _source: null, + _message: null, + + initialize: function(source, message) { + this._source = source; + this._message = message; + }, + toString: function() { + return this.__class__.__name__ + " from TimeSide." + this._source.__class__.__name__ + ": " + this._message; - } -}); + } + }); -$N.Class.create("RequiredOptionError", $N.Exception, { - initialize: function($super, source, optionName) { - $super(source, "missing '" + optionName + "' required option"); - } -}); + $N.Class.create("RequiredOptionError", $N.Exception, { + initialize: function($super, source, optionName) { + $super(source, "missing '" + optionName + "' required option"); + } + }); -$N.Class.create("RequiredArgumentError", $N.Exception, { - initialize: function($super, source, optionName) { - $super(source, "missing '" + optionName + "' required argument"); - } -}); + $N.Class.create("RequiredArgumentError", $N.Exception, { + initialize: function($super, source, optionName) { + $super(source, "missing '" + optionName + "' required argument"); + } + }); -$N.notifyScriptLoad(); + $N.notifyScriptLoad(); }); diff --git a/telemeta/htdocs/timeside/src/markermap.js b/telemeta/htdocs/timeside/src/markermap.js index 29ade71f..8a285c76 100644 --- a/telemeta/htdocs/timeside/src/markermap.js +++ b/telemeta/htdocs/timeside/src/markermap.js @@ -7,129 +7,148 @@ TimeSide(function($N, $J) { -$N.Class.create("MarkerMap", $N.Core, { - markers: null, - - initialize: function($super, markers) { - $super(); - if (!markers) - markers = []; - this.markers = markers; - }, - - toArray: function() { - return [].concat(this.markers); - }, - - byIndex: function(index) { - return this.markers[index]; - }, - - byId: function(id) { - var marker = null; - for (var i in this.markers) { - if (this.markers[i].id == id) { - marker = this.markers[i]; - break; + $N.Class.create("MarkerMap", $N.Core, { + markers: null, + + initialize: function($super, markers) { + $super(); + if (!markers){ + markers = []; } - } - return marker; - }, - - indexOf: function(marker) { - var index = null; - for (var i in this.markers) { - if (this.markers[i].id == marker.id) { - index = parseInt(i); - break; + this.markers = markers; + }, + + toArray: function() { + return [].concat(this.markers); + }, + + byIndex: function(index) { + return this.markers[index]; + }, + + byId: function(id) { + var marker = null; + for (var i in this.markers) { + if (this.markers[i].id == id) { + marker = this.markers[i]; + break; + } } - } - return index; - }, - - _reorder: function() { - this.markers.sort(this.compare); - for (var i in this.markers) { - this.fire('indexchange', {marker: this.markers[i], index: parseInt(i)}); - } - }, - - add: function(offset, desc) { - var id = this.uniqid(); - var marker = {id: id, offset: offset, desc: desc}; - var i = this.markers.push(marker) - 1; - this.fire('add', {marker: marker, index: i}); - this._reorder(); - return marker; - }, - - remove: function(marker) { - if (marker) { - var i = this.indexOf(marker); - this.markers.splice(i, 1); - this.fire('remove', {marker: marker}); + return marker; + }, + + indexOf: function(marker) { + var index = null; + for (var i in this.markers) { + if (this.markers[i].id == marker.id) { + index = parseInt(i); + break; + } + } + return index; + }, + + _reorder: function() { + this.markers.sort(this.compare); + for (var i in this.markers) { + this.fire('indexchange', { + marker: this.markers[i], + index: parseInt(i) + }); + } + }, + + add: function(offset, desc) { + var id = this.uniqid(); + var marker = { + id: id, + offset: offset, + desc: desc + }; + var i = this.markers.push(marker) - 1; + this.fire('add', { + marker: marker, + index: i + }); this._reorder(); - } - return marker; - }, - - compare: function(marker1, marker2) { - if (marker1.offset > marker2.offset) - return 1; - if (marker1.offset < marker2.offset) - return -1; - return 0; - }, - - move: function(marker, offset) { - oldMarkers = [].concat(this.markers); - marker.offset = offset; - this._reorder(); - }, - - getPrevious: function(offset, skip) { - var marker = null; - if (!skip) skip = 0; - markers = [].concat(this.markers).reverse(); - $J(markers).each(function(i, m) { - if (offset > m.offset && !(skip--)) { - marker = m; - return false; + return marker; + }, + + remove: function(marker) { + if (marker) { + var i = this.indexOf(marker); + this.markers.splice(i, 1); + this.fire('remove', { + marker: marker + }); + this._reorder(); + } + return marker; + }, + + compare: function(marker1, marker2) { + if (marker1.offset > marker2.offset){ + return 1; } - }); - return marker; - }, - - getNext: function(offset, skip) { - var marker = null; - if (!skip) skip = 0; - $J(this.markers).each(function(i, m) { - if (offset < m.offset && !(skip--)) { - marker = m; - return false; + if (marker1.offset < marker2.offset){ + return -1; } - }); - return marker; - }, + return 0; + }, - each: function(callback) { - $J(this.markers).each(callback); - }, + move: function(marker, offset) { + oldMarkers = [].concat(this.markers); + marker.offset = offset; + this._reorder(); + }, - _toString: function() { - var s = "\n\n"; - for (var i in this.markers) { + getPrevious: function(offset, skip) { + var marker = null; + if (!skip) { + skip = 0; + } + markers = [].concat(this.markers).reverse(); + $J(markers).each(function(i, m) { + if (offset > m.offset && !(skip--)) { + marker = m; + return false; + } + }); + return marker; + }, + + getNext: function(offset, skip) { + var marker = null; + if (!skip) { + skip = 0; + } + $J(this.markers).each(function(i, m) { + if (offset < m.offset && !(skip--)) { + marker = m; + return false; + } + }); + return marker; + }, + + each: function(callback) { + $J(this.markers).each(callback); + }, + + _toString: function() { + var s = "\n\n"; + for (var i in this.markers) { marker = this.markers[i]; - s+="\n\t"; //+marker._toString(); - s+="" + s+="\n\t"; //+marker._toString(); + s+="" + } + s+="\n\n"; + return s; } - s+="\n\n"; - return s; - } -}); + }); -$N.notifyScriptLoad(); + $N.notifyScriptLoad(); }); diff --git a/telemeta/templates/telemeta_default/base.html b/telemeta/templates/telemeta_default/base.html index 7d368baf..65c9f9ce 100644 --- a/telemeta/templates/telemeta_default/base.html +++ b/telemeta/templates/telemeta_default/base.html @@ -13,8 +13,12 @@ {% endblock %} + + + {% block extra_javascript %}{% endblock %} diff --git a/telemeta/web/base.py b/telemeta/web/base.py index 2407adac..bcac36f7 100644 --- a/telemeta/web/base.py +++ b/telemeta/web/base.py @@ -116,7 +116,7 @@ class WebView(object): def item_detail(self, request, public_id, template='telemeta/mediaitem_detail.html'): """Show the details of a given item""" item = MediaItem.objects.get(public_id=public_id) - + print 'ok' formats = [] for encoder in self.encoders: formats.append({'name': encoder.format(), 'extension': encoder.file_extension()}) @@ -530,6 +530,10 @@ class WebView(object): def logout(self, request): auth.logout(request) return redirect('telemeta-home') + + @jsonrpc_method('telemeta.add_marker_test') + def add_marker_test(request,marker): + print "Received" @jsonrpc_method('telemeta.add_marker') def add_marker(request, marker):