aboutsummaryrefslogtreecommitdiffstats
path: root/template
diff options
context:
space:
mode:
authorrvelices <rv-github@modusoptimus.com>2008-07-02 01:11:26 +0000
committerrvelices <rv-github@modusoptimus.com>2008-07-02 01:11:26 +0000
commit644f8ee621549ce1a60f3e1e0dbff83eab8e0c87 (patch)
treebb44ac813d654261bcdc3b5dfd2bc0e5d7c66b53 /template
parentd0e86480c46b6f48dfb37284b20b99b9ab862e9a (diff)
- first use of web services as Ajax: change the privacy level directly from the picture page
git-svn-id: http://piwigo.org/svn/trunk@2413 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r--template-common/scripts.js105
-rw-r--r--template/yoga/picture.tpl28
2 files changed, 132 insertions, 1 deletions
diff --git a/template-common/scripts.js b/template-common/scripts.js
index 83f4815e7..452be1699 100644
--- a/template-common/scripts.js
+++ b/template-common/scripts.js
@@ -72,3 +72,108 @@ function popuphelp(url)
);
}
+
+
+Function.prototype.pwgBind = function() {
+ var __method = this, object = arguments[0], args = new Array();
+ for (var i=1; i<arguments.length; i++)
+ args[i-1] = arguments[i];
+ return function() { return __method.apply(object, args); }
+}
+
+PwgWS = function(urlRoot)
+{
+ this.urlRoot = urlRoot;
+ this.options = {
+ method: "GET",
+ async: true,
+ onFailure: null,
+ onSuccess: null
+ };
+};
+
+PwgWS.prototype = {
+
+ callService : function(method, parameters, options)
+ {
+ if (options)
+ {
+ for (var property in options)
+ this.options[property] = options[property];
+ }
+ try { this.transport = new XMLHttpRequest();}
+ catch(e) {
+ try { this.transport = new ActiveXObject('Msxml2.XMLHTTP'); }
+ catch(e) {
+ try { this.transport = new ActiveXObject('Microsoft.XMLHTTP'); }
+ catch (e){
+ dispatchError(0, "Cannot create request object");
+ }
+ }
+ }
+ this.transport.onreadystatechange = this.onStateChange.pwgBind(this);
+
+ var url = this.urlRoot;
+ url += "ws.php?format=json&method="+method;
+ if (parameters)
+ {
+ for (var property in parameters)
+ {
+ if ( typeof parameters[property] == 'object' && parameters[property])
+ {
+ for (var i=0; i<parameters[property].length; i++)
+ url += "&"+property+"[]="+parameters[property][i];
+ }
+ else
+ url += "&"+property+"="+parameters[property];
+ }
+ }
+ this.transport.open(this.options.method, url, this.options.async);
+ this.transport.send(null);
+ },
+
+ onStateChange: function() {
+ var readyState = this.transport.readyState;
+ if (readyState == 4)
+ this.respondToReadyState(this.transport.readyState);
+ },
+
+ dispatchError: function( httpCode, text )
+ {
+ !this.options.onFailure || this.options.onFailure( httpCode, text);
+ },
+
+ respondToReadyState: function(readyState)
+ {
+ var transport = this.transport;
+ if (readyState==4 && transport.status == 200)
+ {
+ var resp;
+ try {
+ eval('resp = ' + transport.responseText);
+ }
+ catch (e)
+ {
+ this.dispatchError( 200, e.message + '\n' + transport.responseText.substr(0,256).escapeHTML() );
+ }
+ if (resp!=null)
+ {
+ if (resp.stat==null)
+ this.dispatchError( 200, "Invalid response" );
+ else if (resp.stat=='ok')
+ {
+ if (this.options.onSuccess) this.options.onSuccess( resp.result );
+ }
+ else
+ this.dispatchError( 200, resp.err + " " + resp.message);
+ }
+ }
+ if (readyState==4 && transport.status != 200)
+ this.dispatchError( transport.status, transport.statusText );
+ },
+
+
+ transport: null,
+ urlRoot: null,
+ options: {}
+}
diff --git a/template/yoga/picture.tpl b/template/yoga/picture.tpl
index fc5fce450..e52a7a7a7 100644
--- a/template/yoga/picture.tpl
+++ b/template/yoga/picture.tpl
@@ -117,7 +117,7 @@
<td class="value">
{if isset($related_tags)}
{foreach from=$related_tags item=tag name=tag_loop}{if !$smarty.foreach.tag_loop.first}, {/if}
- <a href="{$tag.U_TAG}">{$tag.NAME}</a>{/foreach}
+ <a href="{$tag.URL}">{$tag.name}</a>{/foreach}
{/if}
</td>
</tr>
@@ -137,6 +137,32 @@
<td class="label">{'Visits'|@translate}</td>
<td class="value">{$INFO_VISITS}</td>
</tr>
+ {if isset($available_permission_levels) }
+ <tr>
+ <td class="label">{'Privacy level'|@translate}:</td>
+ <td class="value">
+<script type="text/javascript">
+{literal}function setPrivacyLevel(selectElement, rootUrl, id, level)
+{
+selectElement.disabled = true;
+var y = new PwgWS(rootUrl);
+
+y.callService(
+ "pwg.images.setPrivacyLevel", {image_id: id, level:level} ,
+ {
+ onFailure: function(num, text) { selectElement.disabled = false; alert(num + " " + text); },
+ onSuccess: function(result) { selectElement.disabled = false; }
+ }
+ );
+}{/literal}
+</script>
+ <select onchange="setPrivacyLevel(this, '{$ROOT_URL|@escape:'javascript'}', {$current.id}, this.options[selectedIndex].value)">
+ {foreach from=$available_permission_levels item=level}
+ <option value="{$level}"{if $current.level==$level} selected="selected"{/if}>{$pwg->l10n($pwg->sprintf('Level %d',$level))}</option>
+ {/foreach}
+ </select>
+ </td></tr>
+ {/if}
{if isset($rate_summary) }
<tr>
<td class="label">{'Average rate'|@translate}</td>