web/data/cubicweb.iprogress.js
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 20 May 2010 20:47:55 +0200
changeset 5556 9ab2b4c74baf
parent 4700 b981c7d3e3c0
child 5658 7b9553a9db65
permissions -rw-r--r--
[entity] introduce a new 'adapters' registry This changeset introduces the notion in adapters (as in Zope Component Architecture) in a cubicweb way, eg using a specific registry of appobjects. This allows nicer code structure, by avoid clutering entity classes and moving code usually specific to a place of the ui (or something else) together with the code that use the interface. We don't use actual interface anymore, they are implied by adapters (which may be abstract), whose reg id is an interface name. Appobjects that used to 'implements(IFace)' should now be rewritten by: * coding an IFaceAdapter(EntityAdapter) defining (implementing if desired) the interface, usually with __regid__ = 'IFace' * use "adaptable('IFace')" as selector instead Also, the implements_adapter_compat decorator eases backward compatibility with adapter's methods that may still be found on entities implementing the interface. Notice that unlike ZCA, we don't support automatic adapters chain (yagni?). All interfaces defined in cubicweb have been turned into adapters, also some new ones have been introduced to cleanup Entity / AnyEntity classes namespace. At the end, the pluggable mixins mecanism should disappear in favor of adapters as well.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4700
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     1
function ProgressBar() {
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     2
    this.budget = 100;
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     3
    this.todo = 100;
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     4
    this.done = 100;
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     5
    this.color_done = "green";
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     6
    this.color_budget = "blue";
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     7
    this.color_todo = "#cccccc"; //  grey
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     8
    this.height = 16;
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     9
    this.middle = this.height/2;
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    10
    this.radius = 4;
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    11
}
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    12
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    13
ProgressBar.prototype.draw_one_rect = function(ctx, pos, color, fill) {
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    14
    ctx.beginPath();
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    15
    ctx.lineWidth = 1;
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    16
    ctx.strokeStyle = color;
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    17
    if (fill) {
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    18
	ctx.fillStyle = color;
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    19
	ctx.fillRect(0,0,pos,this.middle*2);
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    20
    } else {
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    21
	ctx.lineWidth = 2;
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    22
	ctx.strokeStyle = "black";
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    23
	ctx.moveTo(pos,0);
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    24
	ctx.lineTo(pos,this.middle*2);
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    25
	ctx.stroke();
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    26
    }
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    27
};
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    28
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    29
ProgressBar.prototype.draw_one_circ = function(ctx, pos, color) {
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    30
    ctx.beginPath();
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    31
    ctx.lineWidth = 2;
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    32
    ctx.strokeStyle = color;
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    33
    ctx.moveTo(0,this.middle);
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    34
    ctx.lineTo(pos,this.middle);
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    35
    ctx.arc(pos,this.middle,this.radius,0,Math.PI*2,true);
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    36
    ctx.stroke();
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    37
};
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    38
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    39
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    40
ProgressBar.prototype.draw_circ = function(ctx) {
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    41
    this.draw_one_circ(ctx,this.budget,this.color_budget);
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    42
    this.draw_one_circ(ctx,this.todo,this.color_todo);
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    43
    this.draw_one_circ(ctx,this.done,this.color_done);
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    44
};
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    45
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    46
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    47
ProgressBar.prototype.draw_rect = function(ctx) {
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    48
    this.draw_one_rect(ctx,this.todo,this.color_todo,true);
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    49
    this.draw_one_rect(ctx,this.done,this.color_done,true);
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    50
    this.draw_one_rect(ctx,this.budget,this.color_budget,false);
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    51
};
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    52
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    53
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    54
function draw_progressbar(cid, done, todo, budget, color) {
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    55
    var canvas = document.getElementById(cid);
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    56
    if (canvas.getContext) {
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    57
        var ctx = canvas.getContext("2d");
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    58
	var bar = new ProgressBar();
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    59
	bar.budget = budget;
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    60
	bar.todo = todo;
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    61
	bar.done = done;
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    62
        bar.color_done = color;
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    63
	bar.draw_rect(ctx);
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    64
    }
b981c7d3e3c0 [iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    65
}