-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathnumericpointpicker.js
83 lines (70 loc) · 2.17 KB
/
numericpointpicker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
function NumericPointPicker() {
"use strict";
var pointSeq = [0, 1, 2, 3, 5, 8, 13, 20];
var parser = positiveNumericParser;
var that=this;
var debug=false;
var pickerElement;
var log = function(message) {
tp.utils.log("Numeric point picker", message);
};
this.showPointPicker = function(cardElement){
// check if already installed
if($(cardElement).find('.picker').length) {
if(debug)log("already installed!");
return;
}
var pickers = '<span class="point-value">?</span> ';
for (var i=0; i < pointSeq.length; i++) {
if(debug)log(i+"::"+pointSeq[i]);
pickers += '<span class="point-value">' + pointSeq[i] + '</span> ';
}
if(debug)log(pointSeq.length+" points installed in picker : "+pointSeqs);
var picker = "<div class='picker'>" + pickers + "</div>";
$(".card-detail-title .edit-controls").append(picker);
pickerElement = picker;
$(".point-value").click(that.updatePoint);
};
this.uninstall=function() {
log("removing point picker");
if (pickerElement != null) {
$(pickerElement).unwrap();
log("removed: point picker");
}
pickerElement = null;
};
this.updatePoint=function(){
var value = $(this).text();
var $text = $(".card-detail-title .edit textarea");
if ($text.length==0) {
alertBrokenAPI("Point Picker : text not found");
return;
}
var text = $text.val();
// replace our new
$text[0].value=parser.parsePoints(text)?text.replace(parser.reg, '('+value+') '):text+' ('+value+')';
// then click our button so it all gets saved away
$(".card-detail-title .edit .js-save-edit").click();
return false;
};
// only allow numbers, skip everything else...
this.parsePointPickerFrom=function(text) {
var stringArray= text.split(',');
var pointsArray = [];
for (var i=0; i < stringArray.length; i++) {
var val = $.trim(stringArray[i]);
if (tp.utils.isNumber(val)) {
pointsArray.push(Number(val));
}
}
if(debug)log("NUM::computed :"+pointsArray.length+" points from "+text);
return pointsArray;
};
this.setSequence=function(sequence) {
//TODO test tableau! underscore
pointSeq = sequence;
};
this.toString = function() {
return "Alphanumeric : "+pointSeq.toString();
};
}