Forked from an inaccessible project.
-
Jonathan Wilkes authoredJonathan Wilkes authored
dialog_gatom.html 8.79 KiB
<!DOCTYPE html>
<html>
<head>
<link id="page_style" rel="stylesheet" type="text/css" href="css/default.css">
</head>
<body id="iemgui_dialog_body">
<div class="container">
<form>
<fieldset>
<legend data-i18n="gatom.prop.gatom"></legend>
<table class="pairs">
<tr class="width prop">
<td>
<label data-i18n="[title]iem.prop.width_tt">
<span data-i18n="iem.prop.width"></span>
</label>
</td>
<td data-i18n="[title]iem.prop.width_tt">
<input type="text" id="width" name="width">
</td>
<td>
</td>
<td>
</td>
</tr>
<tr class="draglo prop pair">
<td>
<label data-i18n="[title]iem.prop.minimum_tt">
<span data-i18n="iem.prop.minimum"></span>
</label>
</td>
<td data-i18n="[title]iem.prop.minimum_tt">
<input type="text" id="minimum-range" name="minimum-range">
</td>
<td>
<label data-i18n="[title]iem.prop.maximum_tt">
<span data-i18n="iem.prop.maximum"></span>
</label>
</td>
<td data-i18n="[title]iem.prop.maximum_tt">
<input type="text" id="maximum-range" name="maximum-range">
</td>
</tr>
<tr>
<td>
<label data-i18n="[title]iem.prop.send_tt">
<span data-i18n="iem.prop.send"></span>
</label>
</td>
<td colspan="3">
<input type="text" id="send-symbol" name="send-symbol">
</td>
</tr>
<tr>
<td>
<label data-i18n="[title]iem.prop.receive_tt">
<span data-i18n="iem.prop.receive"></span>
</label>
</td>
<td colspan="3">
<input type="text" id="receive-symbol" name="receive-symbol">
</td>
</tr>
<tr>
<td>
<label data-i18n="[title]gatom.prop.label_tt">
<span data-i18n="gatom.prop.label"></span>
</label>
</td>
<td colspan="3">
<input type="text" id="label" name="label">
</td>
</tr>
<tr>
<td>
<label data-i18n="[title]gatom.prop.labelpos_tt">
<span data-i18n="gatom.prop.labelpos"></span>
</label>
</td>
<td colspan="3">
<label class="points"
data-i18n="[title]gatom.prop.labelpos_tt">
<input class="label-pos"
type="radio"
id="labelpos_left"
value="2"
name="labelpos">
<span data-i18n="gatom.prop.label_top"></span>
<br/>
<input class="array-style"
type="radio"
id="labelpos_left"
value="0"
name="labelpos">
<span data-i18n="gatom.prop.label_left"></span>
<input class="array-style"
type="radio"
id="labelpos_right"
value="1"
name="labelpos">
<span data-i18n="gatom.prop.label_right"></span>
<br/>
<input class="array-style"
type="radio"
id="labelpos_bottom"
value="3"
name="labelpos">
<span data-i18n="gatom.prop.label_bottom"></span>
</label>
</table>
</fieldset>
<div class="submit_buttons">
<button type="button" onClick="ok()" data-i18n="[title]iem.prop.ok_tt">
<span data-i18n="iem.prop.ok"></span>
</button>
<button type="button" onClick="apply()" data-i18n="[title]iem.prop.apply_tt">
<span data-i18n="iem.prop.apply"></span>
</button>
<button type="button" onClick="cancel()" data-i18n="[title]iem.prop.cancel_tt">
<span data-i18n="iem.prop.cancel"></span>
</button>
</div>
</form>
</div>
<script>
'use strict';
var nw = require('nw.gui');
var pdgui = require('./pdgui.js');
// For translations
var l = pdgui.get_local_string;
pdgui.skin.apply(this);
var pd_object_callback;
function ok() {
apply();
cancel();
}
function substitute_space(arg) {
var fake_space = String.fromCharCode(11);
return arg.split(' ').join(fake_space);
}
function strip_problem_chars(arg) {
var problem_chars = [';', ',', '{', '}', '\\'];
var ret = arg;
for(var i = 0; i < problem_chars.length; i++) {
ret = ret.split(';').join('');
}
return ret;
}
function gatom_escape(str) {
var arr, i, ret;
if (str.length === 0) {
ret = '-';
} else if (str.slice(0,1) === '-') {
ret = '-' + str;
} else {
arr = str.split('');
for (i = 0; i < arr.length; i++) {
if (arr[i] === '$') {
arr[i] = '#';
}
}
ret = arr.join('');
}
return strip_problem_chars(ret);
}
function apply() {
pdgui.gui_post("we're applying gatom changes!");
pdgui.pdsend([pd_object_callback, 'param',
+document.getElementById('width').value,
+document.getElementById('minimum-range').value,
+document.getElementById('maximum-range').value,
gatom_escape(document.getElementById('label').value),
document.querySelector('input[name="labelpos"]:checked').value,
gatom_escape(document.getElementById('receive-symbol').value),
gatom_escape(document.getElementById('send-symbol').value)
].join(' '));
}
function cancel() {
pdgui.gui_post("closing the window at this point");
//window.close(true);
pdgui.pdsend(pd_object_callback + " cancel");
}
// This gets called from the nw_create_window function in index.html
// It provides us with our window id from the C side. Once we have it
// we can create the menu and register event callbacks
function register_canvas_id(gfxstub, attr_array) {
pd_object_callback = gfxstub;
console.log('attr array is ' + attr_array.toString());
for (var i = 0; i < attr_array.length; i+=2) {
console.log(attr_array[i] + ": " + attr_array[i+1]);
}
add_events(gfxstub);
// not sure that we need this for properties windows
//pdgui.canvas_map(gfxstub);
translate_form();
populate_form(attr_array);
// We don't turn on rendering of the "container" div until
// We've finished displaying all the spans and populating the
// labels and form elements. That makes it more efficient and
// snappier, at least on older machines.
document.getElementsByClassName('container')[0]
.style.setProperty('display', 'inline');
pdgui.resize_window(pd_object_callback);
}
function tr_text(id) {
var elem = document.getElementById('iem.prop.' + id);
elem.textContent = l('iem.prop.' + id);
}
// Stop-gap translator
function translate_form() {
var i
var elements = document.querySelectorAll('[data-i18n]');
for (i = 0; i < elements.length; i++) {
var data = elements[i].dataset.i18n;
if (data.slice(0,7) === '[title]') {
elements[i].title = l(data.slice(7));
} else {
elements[i].textContent = l(data);
}
}
}
function get_attr(name, attrs) {
return attrs[attrs.indexOf(name)+1];
}
function get_elem(name) {
return document.getElementById(name);
}
function populate_form(attr_array) {
var label, snd, rcv, labelpos, i, radios;
get_elem('width').value = get_attr('width', attr_array);
get_elem('minimum-range').value = get_attr('draglo', attr_array);
get_elem('maximum-range').value = get_attr('draghi', attr_array);
label = get_attr('label', attr_array);
get_elem('label').value = label === '-' ? '' : label;
snd = get_attr('send-symbol', attr_array);
get_elem('send-symbol').value = snd === '-' ? '' : snd;
rcv = get_attr('receive-symbol', attr_array);
get_elem('receive-symbol').value = rcv === '-' ? '' : rcv;
labelpos = get_attr('labelpos', attr_array);
radios = document.getElementsByName('labelpos');
for (i = 0; i < radios.length; i++) {
if (+radios[i].value === labelpos) {
radios[i].checked = true;
}
}
}
function add_events(name) {
// closing the Window
nw.Window.get().on("close", function() {
// this needs to do whatever the "cancel" button does
//pdgui.pdsend(name + " menuclose 0");
//cancel();
pdgui.remove_dialogwin(pd_object_callback);
this.close(true);
});
pdgui.dialog_bindings(name);
}
</script>
</body>
</html>