[LON-CAPA-cvs] cvs: modules /matthew/newrat Conditional.js HR.js Resource.js test.js

matthew lon-capa-cvs@mail.lon-capa.org
Tue, 19 Mar 2002 22:06:52 -0000


This is a MIME encoded message

--matthew1016575612
Content-Type: text/plain

matthew		Tue Mar 19 17:06:52 2002 EDT

  Modified files:              
    /modules/matthew/newrat	Conditional.js HR.js Resource.js test.js 
  Log:
  Trying to match colors, add 'edit' mode.
  
  
--matthew1016575612
Content-Type: text/plain
Content-Disposition: attachment; filename="matthew-20020319170652.txt"

Index: modules/matthew/newrat/Conditional.js
diff -u modules/matthew/newrat/Conditional.js:1.1 modules/matthew/newrat/Conditional.js:1.2
--- modules/matthew/newrat/Conditional.js:1.1	Tue Mar 19 13:46:53 2002
+++ modules/matthew/newrat/Conditional.js	Tue Mar 19 17:06:52 2002
@@ -1,7 +1,7 @@
 // 
 // Conditional.js
 // 
-// $Id: Conditional.js,v 1.1 2002/03/19 18:46:53 matthew Exp $
+// $Id: Conditional.js,v 1.2 2002/03/19 22:06:52 matthew Exp $
 //
 // Child of Item.js
 // A Conditional is a file in the lon-capa system.
@@ -11,21 +11,24 @@
 function Conditional_load(text) {}
 function Conditional_save()     {}
 
-function Conditional_draw() {
+function Conditional_draw(mode) {
     var result = '';
-    var mode = 'other';
     if (mode == 'icon') {
     } else if (mode == 'edit') {
     } else if (mode == 'normal') {
-        result += '<table bgcolor="#7777cc" width="100%">';
+        result += '<table bgcolor="'+this.get_color()+'" width="100%">';
         result += '<tr><td colspan="2">Conditional</td></tr>';
-        result += '<tr><td>Condition:</td><td>'+this.condition+'</td></tr>';
+        result += '<tr><td>Condition:</td><td width="90%">'+this.condition;
+        result += '</td></tr>';
+        result += '<tr><td>Effect:</td><td>'+this.effect+'</td></tr>';
         result += '</table><br \>';
     } else if (mode == 'full') {
-        result += '<table bgcolor="#7777cc" width="100%">';
+        result += '<table bgcolor="'+this.get_color()+'" width="100%">';
         result += '<tr><td colspan="2">Conditional</td></tr>';
-        result += '<tr><td>Condition:</td><td>'+this.condition+'</td></tr>';
-        result+='<tr><td valign="top" >Parameters:</td><td>';
+        result += '<tr><td>Condition:</td><td width="90%">'+this.condition;
+        result += '</td></tr>';
+        result += '<tr><td>Effect:</td><td>'+this.effect+'</td></tr>';
+        result += '<tr><td valign="top" >Parameters:</td><td>';
         for (var i=0; i<this.parms.length; i++) {
             if (this.parms[i] != null) {
                 result += this.parms[i].draw() + "<br />";
@@ -38,17 +41,39 @@
     return result;
 }
 
+function Conditional_get_color() {
+   if (this.effect == 'stop')  { return '#EEAAAA'; }
+   if (this.effect == 'force') { return '#AAAAEE'; }
+   return '#DDDDDD';
+}
+
 function Conditional_undo() {}
 function Conditional_redo() {}
 
 function Conditional_set_cond(condition) { this.condition=condition; }
 function Conditional_get_cond(condition) { return this.condition;    }
 
+function Conditional_get_effect() { return this.effect; }
+function Conditional_set_effect(effect) {
+    if ((effect != "stop") && 
+        (effect != "force") && 
+        (effect != "recommend")) {
+        alert("Attempt to set bogus condition type");
+        return;
+    }
+    this.effect = effect;
+    return;
+}
+
+
 function Conditional(condition) {
     this.parms = new Array();
+    this.condition = '';
+    this.effect = "stop";
     //
     this.set_cond = Conditional_set_cond;
     this.get_cond = Conditional_get_cond;
+    this.get_color = Conditional_get_color;
     //
     this.set_type('condition');
     if (arguments.length >= 1) { this.set_cond(condition);}
Index: modules/matthew/newrat/HR.js
diff -u modules/matthew/newrat/HR.js:1.1 modules/matthew/newrat/HR.js:1.2
--- modules/matthew/newrat/HR.js:1.1	Tue Mar 19 13:46:53 2002
+++ modules/matthew/newrat/HR.js	Tue Mar 19 17:06:52 2002
@@ -1,7 +1,7 @@
 // 
 // HR.js
 //
-// $Id: HR.js,v 1.1 2002/03/19 18:46:53 matthew Exp $
+// $Id: HR.js,v 1.2 2002/03/19 22:06:52 matthew Exp $
 //
 // Child of Item.js
 // A HR is a horizontal rule which can be held inside a page.
@@ -15,11 +15,11 @@
     if (mode == 'icon') {
     } else if (mode == 'edit') {
     } else if (mode == 'normal') {
-        result += '<table bgcolor="#00cc00" width="100%">';
+        result += '<table bgcolor="#8888FF" width="100%">';
         result += '<tr><td>Horizontal Rule</td></tr>';
         result += '</table><br \>';
     } else if (mode == 'full') {
-        result += '<table bgcolor="#cc8888" width="100%">';
+        result += '<table bgcolor="#8888FF" width="100%">';
         result += '<tr><td>Horizontal Rule</td></tr>';
         result += '<tr><td valign="top" >Parameters:</td><td>';
         for (var i=0; i<this.parms.length; i++) {
Index: modules/matthew/newrat/Resource.js
diff -u modules/matthew/newrat/Resource.js:1.1 modules/matthew/newrat/Resource.js:1.2
--- modules/matthew/newrat/Resource.js:1.1	Tue Mar 19 13:46:53 2002
+++ modules/matthew/newrat/Resource.js	Tue Mar 19 17:06:52 2002
@@ -1,7 +1,7 @@
 // 
 // Resource.js
 //
-// $Id: Resource.js,v 1.1 2002/03/19 18:46:53 matthew Exp $
+// $Id: Resource.js,v 1.2 2002/03/19 22:06:52 matthew Exp $
 //
 // Child of Item.js
 // A Resource is a file in the lon-capa system.
@@ -16,20 +16,20 @@
 function Resource_draw(mode) {
     var result = '';
     if (mode == 'icon') {
-    } else if (mode == 'edit') {
     } else if (mode == 'normal') {
-        result+='<table bgcolor="#00cc00" width="100%" >';
+        result+='<table bgcolor="'+this.get_color()+'" width="100%" >';
         result+='<tr><td colspan="2">Resource</td></tr>';
         result+='<tr><td>Title:</td><td width="100%">'+this.Title+'</td></tr>';
         result+='<tr><td>URL:</td><td>'+this.url+'</td></tr>';
+        result+='<tr><td>use:</td><td>'+this.use+'</td></tr>';
         result+='<tr><td>icon:</td><td>'+this.icon+'</td></tr>';
         result+='</table><br \>';
-
     } else if (mode == 'full') {
-        result+='<table bgcolor="#00cc00" width="100%" >';
+        result+='<table bgcolor="'+this.get_color()+'" width="100%" >';
         result+='<tr><td colspan="2">Resource</td></tr>';
         result+='<tr><td>Title:</td><td width="100%">'+this.Title+'</td></tr>';
         result+='<tr><td>URL:</td><td>'+this.url+'</td></tr>';
+        result+='<tr><td>use:</td><td>'+this.use+'</td></tr>';
         result+='<tr><td>icon:</td><td>'+this.icon+'</td></tr>';
         result+='<tr><td valign="top" >Parameters:</td><td>';
         for (var i=0; i<this.parms.length; i++) {
@@ -39,11 +39,31 @@
         }
         result+='</td></tr>';
         result+='</table><br \>';
+    } else if (mode == 'edit') {
+        result+='<table bgcolor="'+this.get_color()+'" width="100%" >';
+        result+='<tr><td colspan="2">Resource</td></tr>';
+        result+='<tr><td>Title:</td><td width="100%">';
+        result+=this.textfield('title',this.Title);
+        result+='</td></tr>';
+        result+='<tr><td>URL:</td><td>';
+        result+=this.textfield('url',this.url);
+        result+='</td></tr>';
+        result+='<tr><td>use:</td><td>'+this.use+'</td></tr>';
+        result+='<tr><td>icon:</td><td>'+this.icon+'</td></tr>';
+        result+='</table><br \>';
     } else {
     }
     return result;
 }
 
+function Resource_textfield(name,value) {
+    var result = '';
+    var editsize = 40;
+    result+='<input type="text" maxlength="200" size="'+editsize+'"';
+    result+='name="'+this.id+name+'" value="'+value+'" />';
+    return result;
+}
+
 function Resource_set_title(t) { this.Title=t;      }
 function Resource_get_title()  { return this.Title; }
 function Resource_get_url()    { return this.url;   }  
@@ -62,15 +82,48 @@
     }
 }
 
+function Resource_get_use() { return this.use; }
+function Resource_set_use(value) {
+    if ((value != 'Regular'  ) &&
+        (value != 'Mandatory') &&
+        (value != 'Optional')) {
+        alert("Attempt to assign invalid use to resource");
+        return;
+    }
+    this.use = value;
+}
+
+function Resource_get_color() {
+    return '#AAFFAA';
+    var rc; var gc; var bc;
+    if (this.use == 'Mandatory') { rc='FF'; } else { rc='BB'; }
+    if (this.use == 'Optional')  { gc='BB'; } else { gc='FF'; }
+    if (this.external)           { bc='55'; } else { bc='99'; }
+    return '#'+rc+gc+bc;
+}
+
+function Resource_is_external()     { return this.external; }
+function Resource_set_external()    { this.external = true; }
+function Resource_set_nonexternal() { this.external = false; }
+
 function Resource(title,url) {
     this.set_title = Resource_set_title;
     this.get_title = Resource_get_title;
     this.set_url   = Resource_set_url;
     this.get_url   = Resource_get_url;
+    this.set_use   = Resource_set_use;
+    this.get_use   = Resource_get_use;
+    this.set_external = Resource_set_external;
+    this.set_nonexternal = Resource_set_nonexternal;
+    this.is_external  = Resource_is_external;
+    this.get_color = Resource_get_color;
+    this.textfield = Resource_textfield;
     //
     this.parms = new Array();
     this.title = '';
     this.url   = '';
+    this.use   = 'Regular';
+    this.external = false;
     //
     this.set_type('resource');
     // 
@@ -84,3 +137,5 @@
     this.redo = Resource_redo;
 }
 Resource.prototype = new Item();
+
+
Index: modules/matthew/newrat/test.js
diff -u modules/matthew/newrat/test.js:1.1 modules/matthew/newrat/test.js:1.2
--- modules/matthew/newrat/test.js:1.1	Tue Mar 19 13:46:53 2002
+++ modules/matthew/newrat/test.js	Tue Mar 19 17:06:52 2002
@@ -1,7 +1,7 @@
 //
 // test.js - javascript testing file for new rat objects
 //
-// $Id: test.js,v 1.1 2002/03/19 18:46:53 matthew Exp $
+// $Id: test.js,v 1.2 2002/03/19 22:06:52 matthew Exp $
 //
 // Create a fake sequence...
 var Seq = new Sequence();
@@ -70,9 +70,6 @@
 Seq.add_parm_to('creature','fish','salmon',4);
 Seq.add_parm_to('creature','fish','goldfish',5);
 
-document.writeln(Seq.draw_contents('full'));
-
-
-
-
-
+document.writeln('<form>');
+document.writeln(Seq.draw_contents('edit'));
+document.writeln('</form>');

--matthew1016575612--