Commit 6f380103 authored by Antonin Delpeuch's avatar Antonin Delpeuch
Browse files

First working draft

parent 26ed7c13
......@@ -3,10 +3,10 @@
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://moderation/content/toolbar-events.js" />
<toolbar id="header-view-toolbar">
<toolbarbutton id="hdrModAcceptButton" label="Accepter" oncommand="ToolbarEvents.onAccept(event);" />
<toolbarbutton id="hdrModAcceptButton" class="hdrForwardButton msgHeaderView-button" label="Accepter" oncommand="ToolbarEvents.onAccept(event);" />
</toolbar>
<toolbar id="header-view-toolbar">
<toolbarbutton id="hdrModRejectButton" label="Rejeter" oncommand="ToolbarEvents.onReject(event);" />
<toolbarbutton id="hdrModRejectButton" class="hdrTrashButton msgHeaderView-button" label="Rejeter" oncommand="ToolbarEvents.onReject(event);" />
</toolbar>
</overlay>
var ToolbarEvents = {
currentCookie : "",
onLoad: function() {
// init code
Components.utils.import("resource://gre/modules/FileUtils.jsm");
var messagepane = document.getElementById("messagepane");
if(messagepane)
messagepane.addEventListener("load", ToolbarEvents.updateButtons, true);
......@@ -11,7 +13,23 @@ var ToolbarEvents = {
},
mylog:function(msg)
{
Components.utils.reportError(msg);
var objToString=function(obj, depth){
if(obj+'' == '[object Object]' ||(typeof(obj)=='object'&&(obj instanceof Array))){
var str=obj+" {";
for(var key in obj){
if(obj.hasOwnProperty(key)){
str+="\n";
for(var i =0; i < depth; i++)
str+="\t";
str+=" ["+key+"]=["+objToString(obj[key], depth+1)+"]";
}
}
return str+"}";
}
return obj;
};
Components.utils.reportError(objToString(msg,1));
},
updateButtons: function() {
......@@ -28,19 +46,42 @@ var ToolbarEvents = {
return;
var subject = msg.mime2DecodedSubject;
ToolbarEvents.mylog("subject is "+subject);
ToolbarEvents.mylog(msg);
var re = /moderate ([0-9A-F]{8}) \(([a-z0-9]*)\)/g;
matches = re.exec(subject);
if(matches[1])
acceptButton.label= matches[1];
if(matches[2])
rejectButton.label = matches[2];
if(!matches)
{
acceptButton.label='';
rejectButton.label='';
}
else
{
ToolbarEvents.currentCookie = matches[1];
acceptButton.label='Accepter';
rejectButton.label='Rejeter';
}
},
runCmd: function(action,cookie)
{
ToolbarEvents.mylog("running runCmd");
var process = Components.classes["@mozilla.org/process/util;1"]
.createInstance(Components.interfaces.nsIProcess);
var file = new FileUtils.File("/usr/bin/ssh");
process.init(file);
ToolbarEvents.mylog("delpeuch@clipper \~gourous/bin/su-gourous \~gourous/bin/moderate --"+action+" "+cookie+" delpeuch");
process.runAsync(["delpeuch@clipper", "\~gourous/bin/su-gourous", "\~gourous/bin/moderate", "--"+action, cookie,
"delpeuch"], 6);
},
onAccept: function() {
LOG("onAccept called");
window.open("chrome://moderation/content/hello.xul", "", "chrome");
ToolbarEvents.mylog("running onAccept");
ToolbarEvents.runCmd("transmettre", ToolbarEvents.currentCookie);
},
onReject: function() {
......@@ -52,22 +93,7 @@ var ToolbarEvents = {
var consoleService = Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService);
var str=msg;
if(typeof msg == 'object'){
var objToString=function(obj, depth){
if(obj+'' == '[object Object]' ||(typeof(obj)=='object'&&(obj instanceof Array))){
var str=obj+" {";
for(var key in obj){
if(obj.hasOwnProperty(key)){
str+="\n";
for(var i =0; i < depth; i++)
str+="\t";
str+=" ["+key+"]=["+objToString(obj[key], depth+1)+"]";
}
}
return str+"}";
}
return obj;
};
str=" "+objToString(msg,0);
str=" "+objToString(msg,0);
}
consoleService.logStringMessage(str);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment