Commits

Guido Draheim committed a8cf21f

implement notes_info handling

  • Participants
  • Parent commits 5f0eeff
  • Branches trunk

Comments (0)

Files changed (4)

File src/usernotes/htdocs/js/finya.infovalues.user.js

+// -*- java -*-
+// ==UserScript== 
+// @name          Finya InfoValues
+// @description   Shows the stored info files from the remote host
+// @namespace     http://bitbucket.org/2007/userscriptservernotes
+// @source        http://SERVER/usernotes/scripts
+// @version       6.0.0.0
+// @creator       Guido Draheim <guidod-2007-@gmx.de>
+// @license       http://creativecommons.org/licenses/by-nc-sa/2.0/de/
+// @include       http://www.finya.de/User/profile/*
+// @include       http://finya.de/User/profile/*
+// @include       http://www.finya.de/User/profile/*/*
+// @include       http://finya.de/User/profile/*/*
+// @include       http://www.finya.de/MyProfile/options
+// @include       http://finya.de/MyProfile/options
+// @require       http://SERVER/chrome/usernotes/js/jquery.js
+// @require       http://SERVER/chrome/usernotes/js/bsdsum.js
+// @require       http://SERVER/chrome/usernotes/js/blowfish.js
+// ==/UserScript==
+
+var settings = "usernotes_finyamail_";
+var _url = "http://SERVER/usernotes/info/finya";
+function mail_url() { return gm_getValue(settings+"url", _url); } 
+var _key = "";
+function mail_key() { return gm_getValue(settings+"key", _key); }
+
+function gm_getValue(name, defaultvalue) {
+	var value = GM_getValue(name);
+	if (value == undefined || value == false) return defaultvalue;
+	return value;
+}
+
+function url_data(data) {
+	var text = "";
+	for (var elem in data) {
+		if (text == "") text += "?"; else text += "&";
+		text += encodeURIComponent(elem) + "=" + encodeURIComponent(data[elem]);
+	}
+	return text;
+}
+
+function getResponseXml(elem) {
+    return new DOMParser().parseFromString(elem.responseText, 'text/html');
+}
+
+function CurrentLoginUser() {
+    var login_info = $("#login-info-content");
+    var nick = $(".mlg", login_info);
+    if (nick.size()) {
+        var check = nick.text();
+        GM_log("OK: LOGIN "+check);
+        return check;
+    }
+    GM_log("NA: not logged in?");
+    return "";
+}
+
+function CurrentProfileUser() {
+    var nick = $("#profile-top");
+    if (nick.size()) {
+        var check = nick.text();
+        GM_log("OK: Profile "+check);
+        return check;
+    }
+    GM_log("NA: no user profile?");
+    return "";
+}
+
+function parentsUntil(node, selector) {
+	var N = node;
+	if (N && $(N).is(selector)) return N; else N = N.parent();
+	if (N && $(N).is(selector)) return N; else N = N.parent();
+	if (N && $(N).is(selector)) return N; else N = N.parent();
+	if (N && $(N).is(selector)) return N; else N = N.parent();
+	if (N && $(N).is(selector)) return N; else N = N.parent();
+	if (N && $(N).is(selector)) return N; else N = N.parent();
+	return node;
+}
+
+function string_of_int(num) { return num.toString(10); }
+function int_of_string(val) { return parseInt(val, 10); } 
+function checksumString(buf) { return buf?string_of_int(bsdsum(String(buf))):""; }
+function checksumValue(buf)  { return int_of_string(buf) }
+
+function Blowfish_encrypt(text, key) {
+	if (!text.length) return "";
+	var buf = Utf8.encode(text);
+	var plaintext = buf+("        ".substr( ((buf.length-1)%8)+1 )); // pad8
+	var crypt = new Blowfish(key);
+	return crypt.encrypt(plaintext); // hex-encoded 
+}
+
+function Blowfish_decrypt(text, key) {
+	var crypt = new Blowfish(key);
+	return Utf8.decode(crypt.decrypt(text));
+}
+//========================================================== SETTINGS ====
+
+function findFinyaSettingsTable()
+{
+	// var input = $('#frmOptions');
+	// return parentsUntil(input, "#pgcontent");
+	var input = $('#frmOptions');
+	if (input.size()) return $("#pgcontent");
+	return $("#nothing");
+}
+
+
+function checksumMailKey(event)
+{
+	var target = $('#mail_key_checksum');
+	var phrase = String($(event.target).val());
+	target.text(checksumString(phrase));
+	if (phrase.length < 8 || phrase.length > 56) {
+		target.css("background-color", "#fdd");
+	} else {
+		target.css("background-color", "#def");
+	}
+	return true; // continue processing
+}
+
+function clickedResetMailSettings(event)
+{
+	GM_log("clickedResetMailSettngs");
+	GM_setValue(settings+"url", false);
+	GM_setValue(settings+"key", false);
+	$('#status').text("[zurückgesetzt]");
+	return false; // inhibit normal processing
+}
+
+function clickedSaveMailSettings(event)
+{
+	var val; var def;
+	GM_log("clickedSaveMailSettngs"); 
+
+	val = $('input[name="mail_url"]').val();
+	GM_log("mail_url = "+val); def = _url;
+	if (val == def || ! val) val = false;
+	GM_setValue(settings+"url", val);
+	
+	var val = $('input[name="mail_key"]').val();
+	GM_log("mail_key = "+val); def = _key;
+	if (val == def || ! val) val = false;
+	GM_setValue(settings+"key", val);
+
+	$('#status').text("[gespeichert]");
+	return false; // inhibit normal processing
+}
+
+var heading = "Mail Link Host Settings";
+var heading_id = "maillink_settings";
+var mail_url_name = "Mail-Speicher GET URL (also der verwendete externe Server)";
+var mail_url_desc = ''
+	+ ' Von dieser URL werden die Mail-Texte geholt, die dort'
+	+ ' gespeichert wurden um sie wieder heraussuchen zu können.'
+	+ ' Beachte, dass dies ein extern Server (nicht Finya) ist.';
+var mail_key_name = "Mail Entschlüsselung (mindestens 8 bis zu 56 Zeichen)";
+var mail_key_desc = ''
+	+' Mit dieser Blowfish Schlüsselphrase sollen die Texte entschlüsselt'
+	+' werden wenn sie von der URL geholt wurden. Um die gespeicherten'
+	+' Mails wieder lesen zu können, wird der gleiche Wert benötigt,'
+	+' wie er beim Speichern mit Verschlüsselung verwendet wurde.';
+
+var mail_crc_name = 'Prüfsumme Entschlüssung (bsd sum des Schlüssels)';
+var mail_crc_desc = ''
+	+' Zur Erkennung von versehentlichem Schlüsselwechsel. Dieser Wert'
+	+' wird auch zu jeder Nachricht auf dem Server gespeichert, während'
+	+' die eigentliche Schlüsselphrase NIEMALS zum Server wandert.';
+
+function clickedFinyaMailSettings()
+{
+	GM_log("clickedFinyaMailSettings");
+	var v;
+	var table = findFinyaSettingsTable();
+	var show = $(document.createElement("div"));
+	show.attr("id", "pgcontent");
+	show.append('<h3><b>'+heading+'</b></h3>');
+	v = '<form><table><tr valign="top"><td>';
+	v += '<input type="text" name="mail_url" value="'+mail_url()+'"></input>';
+	v += '</td><td><label for="mail_url"><b>'+mail_url_name+'</b></label>';
+	v += '<br /><small>'+mail_url_desc+'</small>';
+	v += '</td></tr><tr valign="top"><td>';
+	v += '<input type="text" name="mail_key" value="'+mail_key()+'"></input>';
+	v += '</td><td><label for="mail_key"><b>'+mail_key_name+'</b></label>';
+	v += '<br /><small>'+mail_key_desc+'</small>';
+	v += '</td></tr><tr valign="top"><td align="right">';
+	v += '<code id="mail_key_checksum">'+checksumString(mail_key())+'</code>';
+	v += '</td><td><label for="mail_key_checksum"><b>'+mail_crc_name+'</b></label>';
+	v += '<br /><small>'+mail_crc_desc+'</small>';
+	v += '</td></tr></table>';
+	v += '<span class="submit" id="save">ändern</span>';
+	v += '<span class="submit" id="reset">zurücksetzen</span>';
+	v += '<span class="status" id="status"></span>';
+	v += '<style type="text/css"><!--';
+	v += ' .submit { border: 1px solid black; background-color: #EEE;';
+	v += '           padding: 0.5em; margin: 0.5em; }';
+	v += ' .status { color: gray; } '
+	v += '--></style></form>';
+	show.append(v);
+	table.replaceWith(show);
+	$("#save", show).click(clickedSaveMailSettings);
+	$("#reset", show).click(clickedResetMailSettings);
+	$('input[name="mail_key"]').change(checksumMailKey);
+	$('input[name="mail_key"]').keyup(checksumMailKey);
+	$('input[name="mail_key"]').mouseleave(checksumMailKey);
+	return false; // inhibit default processing
+}
+
+function registerFinyaMailSettings()
+{
+	var settings = findFinyaSettingsTable(); 
+	if (settings.size()) {
+		GM_log("registerFinyaMailSettings "+heading_id);
+		var t = '<tr class="line"><td id="@X"><a href="'+mail_url()
+		+'">@N</a></td><td>@V</td></tr>';
+
+		var s = '<div id="@X"><hr /><a href="'+mail_url()
+		+'">@N</a> Einstellungen, derzeit verwendet wird <br /> @V</div>';
+		var mailhost = s;
+		mailhost = mailhost.replace("@X", heading_id);
+		mailhost = mailhost.replace("@N", heading);
+		mailhost = mailhost.replace("@V", mail_url()); 
+		$(settings).append(mailhost);
+		$("#"+heading_id+" a").click(clickedFinyaMailSettings);
+	}
+	return true;
+}
+
+$(window).ready(registerFinyaMailSettings);
+
+//========================================================== THE SCRIPT ====
+
+function successFinyaInfoValues(response) {
+    GM_log("successFinyaInfoValues");
+	var navi = $(".data");
+	if (!navi.size()) {
+		GM_log("OOPS .data is gone");
+		return;
+	}
+    var result = $(".value", response.responseText);
+    GM_log("successFinyaInfoValues: " + result.size());
+    result.each(function () {
+    	GM_log("successFinyaInfoValues = " + $(this).text());
+    	var name = $(this).attr("name").replace(/^value_/,"");
+    	var value = $(this).attr("value");
+        GM_log("successFinyaInfoValues: " + name + " = " + value);
+    	var div = $("<div>");
+    	div.attr("class","data-section");
+    	div.attr("id","mail-count-div");
+    	div.append($("<span>").addClass("data-label").text(name));
+    	div.append($("<span>").addClass("data-value").text(value));
+    	div.appendTo(navi);
+    });
+    var user = CurrentProfileUser();
+    var data = { op: "search", user: user };
+	var link = $("<a>").attr("href", mail_url()+"/search" + url_data(data));
+	var div = $("<div>");
+	div.append(link.text("[edit]")).appendTo(navi);
+}
+
+function errorFinyaInfoValues(response) {
+    GM_log("errorFinyaInfoValues");
+    var result = response.responseText;
+    $("#mail-count").html(result);
+}
+
+function queryFinyaInfoValues(event) {
+	var profile = CurrentProfileUser();
+    GM_log("queryFinyaInfoValues "+profile);
+    var data = { op: "search", user: profile };
+    GM_xmlhttpRequest({ method: "GET", url: mail_url() + url_data(data), 
+		headers: { "Accept":"text/html,text/xml", },
+        onload: successFinyaInfoValues, onerror: errorFinyaInfoValues });
+    return false; // stop default action
+}
+
+function registerFinyaMailCount() {
+    GM_log("registerFinyaInfoValues");
+    var user = CurrentProfileUser();
+    if (user) {
+    	// var navi = $("#link-statementbubble-container");
+    	var navi = $(".data");
+    	if (!navi.size()) {
+    		GM_log("need alternativ anchor");
+    		GM_log("did not found any anchor");
+    		return
+    	} 
+    	queryFinyaInfoValues(user);
+    	GM_log("registerFinyaInfoValues - OK");
+    } else {
+    	GM_log("registerFinyaInfoValues - no user profile");
+    }
+    return true;
+}
+
+$(window).ready(registerFinyaMailCount);

File src/usernotes/htdocs/js/finya.mailcount.user.js

 // @description   The number of stored mails a remote host can be shown
 // @namespace     http://bitbucket.org/2007/userscriptservernotes
 // @source        http://SERVER/usernotes/scripts
-// @version       0.6.0.0
+// @version       6.0.0.0
 // @creator       Guido Draheim <guidod-2007-@gmx.de>
 // @license       http://creativecommons.org/licenses/by-nc-sa/2.0/de/
 // @include       http://www.finya.de/User/profile/*
 }
 
 function errorFinyaMailCount(response) {
-    GM_log("errorFinyaMailLink");
+    GM_log("errorFinyaMailCount");
     var result = response.responseText;
     $("#mail-count").html(result);
 }

File src/usernotes/notes_info.py

             values[elem.note_field] = item
         for item in fields:
             if item.note_field not in values:
-                values[elem.note_field] = Item(note_user, item.note_field, None)
+                values[item.note_field] = Item(note_user, item.note_field, None)
         if not message:
             message = len(values)
         data["domains"] = self._domains(req)

File src/usernotes/templates/form_set_info.html

 				<td colspan="2"><input type="hidden" name="op" value="save" />
 					<div>
 						<label for="user">USER:</label> <input type="text" name="user"
-							value="${note_user}" readonly="readonly"/>
+							value="${note_user}" readonly="readonly" />
 					</div></td>
 			</tr>
 			<tr py:for="item in fields">
 										<option selected="${(option == value or None)}">${option}</option>
 									</py:for>
 								</select>
+								<input type="hidden" name="value_${item.note_field}"
+									value="${value}" typed="${item.note_typed}" class="value"></input>
 							</py:with>
 						</py:when>
 						<py:when test="item.note_typed in ['date']">
 								vars="value = values.get(item.note_field, empty).note_string">
 								<input type="text" name="_${item.note_field}" value="${value}"
 									size="30" />
+								<input type="hidden" name="value_${item.note_field}"
+									value="${value}" typed="${item.note_typed}" class="value"></input>
 							</py:with>
 						</py:when>
 						<py:otherwise>
 								vars="value = values.get(item.note_field, empty).note_string">
 								<input type="text" name="_${item.note_field}" value="${value}"
 									size="55" />
+								<input type="hidden" name="value_${item.note_field}"
+									value="${value}" typed="${item.note_typed}" class="value"></input>
 							</py:with>
 						</py:otherwise>
 					</py:choose></td>