managed close moderate window event and the moderate message argument
authorMatteo Nastasi (mop) <nastasi@alternativeoutput.it>
Tue, 28 May 2013 08:02:10 +0000 (10:02 +0200)
committerMatteo Nastasi (mop) <nastasi@alternativeoutput.it>
Tue, 28 May 2013 08:02:10 +0000 (10:02 +0200)
web/commons.js
web/index_wr.php
web/moderation.php

index f1bab59..1dcb266 100644 (file)
@@ -491,6 +491,7 @@ Moderate.prototype = {
             this.tout = 0;
         }
         if (this.win) {
+            this.win.onbeforeunload = null;
             this.win.close();
             this.win = null;
         }
@@ -531,9 +532,14 @@ Moderate.prototype = {
 
     post_onload: function() {
         $(this.win, 'mainbody').innerHTML = "GHE SEMU";
+        this.win.anc = this;
         this.enabled = true;
     },
 
+    onunload: function() {
+        act_moderate();
+    },
+
     is_enabled: function() {
         return (this.enabled);
     }// ,
@@ -541,7 +547,7 @@ Moderate.prototype = {
     //add: function(item) {
     //    this.item.append(new ModerateItem(item));
     //}
-    // send_mesg("moderate|"+(enable ? "true" | "false"));
+    // send_mesg("moderate|"+(enable ? "false" | "true"));
 
 }
 
@@ -554,15 +560,11 @@ var g_moder = new Moderate();
 
 function act_moderate()
 {
-    send_mesg("moderate|"+(g_moder.is_enabled() ? "true" : "false"));
+    send_mesg("moderate|"+(g_moder.is_enabled() ? "false" : "true"));
 }
 
 
 
-//             send_mesg("moderate|false");
-//             return false;
-//         }
-        
 //         // build table with js
         
 //         g_moder.item = new Array;
index f47071c..fe7a798 100644 (file)
@@ -470,7 +470,7 @@ function index_wr_main(&$room, $remote_addr_full, $get, $post, $cookie)
     else if ($argz[0] == 'moderate') {
         // TODO: add certification check
         if (1 == 1) {
-            if ($user->flags_vlt_get(USER_FLAG_MODER) == 0) {
+            if ($user->flags_vlt_get(USER_FLAG_MODER) == 0 && $argz[1] == 'true') {
                 /* enable moderation */
                 $moder_enable = 'true';
                 $user->flags_vlt_set(USER_FLAG_MODER, USER_FLAG_MODER);
index 482d4ea..ceb06f9 100644 (file)
@@ -6,6 +6,12 @@ window.is_loaded = false;
 window.onload = function() {
     window.is_loaded = true;     
 }
+
+window.onbeforeunload = function() {
+    if (typeof(window.anc) != 'undefined') {
+        window.anc.onunload();
+    }
+}
 // -->
 </script>
 </head>