siesta-lite
Version:
Stress-free JavaScript unit testing and functional testing tool, works in NodeJS and browsers
137 lines (109 loc) • 4.34 kB
HTML
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
<style type="text/css">
.highlight { display: block; background-color: #ddd; }
</style>
<script type="text/javascript">
function highlight() {
document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
}
</script>
</head>
<body onload="prettyPrint(); highlight();">
<pre class="prettyprint lang-js">/*
Siesta 5.6.1
Copyright(c) 2009-2022 Bryntum AB
https://bryntum.com/contact
https://bryntum.com/products/siesta/license
*/
Ext.define('Siesta.Recorder.UI.Editor.Target', {
extend : 'Ext.form.field.ComboBox',
alias : 'widget.targeteditor',
enableKeyEvents : true,
queryMode : 'local',
valueField : 'type',
displayField : 'value',
cls : 'siesta-targeteditor',
targetProperty : 'target',
store : {
proxy : 'memory',
fields : [ 'type', 'value', 'target' ]
},
getTarget : function () {
var value = this.getValue();
if (value && /^!!(.+)/.exec(value)) {
var record = this.store.findRecord('type', value)
// TODO also return 'offset'?
return record ? record.get('target') : null
}
return value ? {
type : 'user',
target : value
} : null
},
setValue : function (value) {
// This method is called with an array of a single record
if (value instanceof Siesta.Recorder.Target) {
if (value.getTarget())
this.callParent([ '!!' + value.getTarget().type ]);
else
this.callParent([ '' ])
} else
this.callParent(arguments)
},
getEditorValue : function (record) {
return record.data[ this.targetProperty ]
},
applyChanges : function (actionRecord) {
var value = this.getValue()
var match
var target = actionRecord.data[ this.targetProperty ]
// Typing 100,200 should mean a coordinate
if (typeof value === 'string' && value.match(/\d*,\d*/)) {
value = value.split(',');
value[0] = parseInt(value[0], 10);
value[1] = parseInt(value[1], 10);
}
if (value && !target) {
target = actionRecord.data[ this.targetProperty ] = new Siesta.Recorder.Target({
targets : [ { type : 'user', target : value } ]
})
}
if (target) {
if (value && (match = /^!!(.+)/.exec(value)))
target.activeTarget = match[ 1 ]
else {
target.setUserTarget(value)
}
// TODO
//actionRecord.afterEdit(this.targetProperty)
}
},
populate : function (target) {
var storeData = [];
target && target.targets.forEach(function (target) {
var type = target.type
value = target.target;
if (type === 'cq' ) {
var splitPos = target.target.indexOf('->');
value = splitPos > 0 ? target.target.split('->').splice(1, 0, '>>').join() : '>>' + target.target
}
storeData.push({
// we add the "!!" before the type, so that "setValue(value)" can distinguish between the value as
// arbitrary string (user input) and value as type name (which should change only the "activeTarget")
type : '!!' + type,
value : value,
target : target
});
});
this.store.loadData(storeData);
}
});
</pre>
</body>
</html>