made generic popup box, will backport other pop-uppy things to it
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 6 Jul 2005 22:09:10 +0000 (22:09 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 6 Jul 2005 22:09:10 +0000 (22:09 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@1084 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/javascript/opac/LoginDialog.js
Open-ILS/src/javascript/opac/MyOPACSPage.js
Open-ILS/src/javascript/util/UserSession.js
Open-ILS/src/javascript/util/webutils.js
Open-ILS/src/javascript/widgets/PopupBox.js [new file with mode: 0644]

index 5e01be4..92d2eb5 100644 (file)
@@ -2,7 +2,6 @@
 function LoginDialog(node, logged_in_callback) {
        this.node = node;
        this.callback = logged_in_callback;
-       this.connected = false;
 }
 
 /* node is the element the dialog should popup under */
index 137aed9..7631b95 100644 (file)
@@ -578,11 +578,11 @@ MyOPACSPage.prototype._drawHolds = function() {
 
        cell = row.insertCell(row.cells.length);
        add_css_class(cell, "my_opac_info_table_header");
-       cell.appendChild(mktext("Notify Email"));
+       cell.appendChild(mktext("Notify Email / Phone"));
 
        cell = row.insertCell(row.cells.length);
        add_css_class(cell, "my_opac_info_table_header");
-       cell.appendChild(mktext("Notify Phone"));
+       cell.appendChild(mktext("Cancel"));
 
        for( var idx = 0; idx != holds.length; idx++ ) {
                _doCallbackDance(table, holds[idx]);
@@ -627,6 +627,8 @@ function _drawHoldsRow(table, hold, record) {
                formats = modsFormatToMARC(record.types_of_resource()[0]);
 
        cell.appendChild(_mkFormatList(formats));
+       cell.noWrap = "nowrap";
+       cell.setAttribute("nowrap", "nowrap");
 
        cell = row.insertCell(row.cells.length);
        add_css_class(cell, "my_opac_profile_cell");
@@ -634,10 +636,84 @@ function _drawHoldsRow(table, hold, record) {
 
        cell = row.insertCell(row.cells.length);
        add_css_class(cell, "my_opac_profile_cell");
-       cell.appendChild(mktext(hold.email_notify()));
+       cell.appendChild(_buildChangeEmailNotify(hold));
+       cell.appendChild(elem("br"));
+       cell.appendChild(_buildChangePhoneNotify(hold));
+
        cell = row.insertCell(row.cells.length);
+       var a = elem("a",{href:"javascript:void(0);",
+                       style:"text-decoration:underline"},null, "Cancel");
+       a.onclick = function(){_cancelHoldRequest(hold);};
        add_css_class(cell, "my_opac_profile_cell");
-       cell.appendChild(mktext(hold.phone_notify()));
+       cell.appendChild(a);
+}
+
+function _cancelHoldRequest(hold) {
+       alert("Canceling hold " + hold.id());
+}
+
+function _buildChangeEmailNotify(hold) {
+       var a = elem("a",{href:"javascript:void(0);",
+                       style:"text-decoration:underline"},null, hold.email_notify());
+       var et1 = elem("input",{type:"text",size:"20"});
+       var et2 = elem("input",{type:"text",size:"20"});
+       var box = new PopupBox(a);
+       var but = elem("input",{type:"submit",value:"Submit"});
+       var can = elem("input",{type:"submit",value:"Cancel"});
+
+       but.onclick = function(){
+               var ret = _submitUpdateNotifyEmail(hold);
+               if(ret) box.hide();
+       }
+       can.onclick = function(){ box.hide(); };
+
+       box.title("Change Holds Notification Email");
+       box.addText("Enter new notification email");
+       box.addNode(et1);
+       box.lines(1);
+       box.addText("Repeat email");
+       box.addNode(et2);
+       box.lines();
+       box.makeGroup([ but, can ]);
+
+       a.onclick = function(){box.show();}
+       return a;
+}
+
+/* return true to show success */
+function _submitUpdateNotifyEmail(hold) {
+       alert("updating email for hold " + hold.id());
+       return true;
+}
+
+function _submitUpdateNotifyPhone(hold) {
+       alert("updating phone for hold " + hold.id());
+       return true;
+}
+
+
+function _buildChangePhoneNotify(hold) {
+       var a = elem("a",{href:"javascript:void(0);",
+                       style:"text-decoration:underline"},null, hold.phone_notify());
+       var et1 = elem("input",{type:"text",size:"10"});
+       var box = new PopupBox(a);
+       var but = elem("input",{type:"submit",value:"Submit"});
+       var can = elem("input",{type:"submit",value:"Cancel"});
+
+       but.onclick = function(){
+               var ret = _submitUpdateNotifyPhone(hold);
+               if(ret) box.hide();
+       }
+       can.onclick = function(){ box.hide(); };
+
+       box.title("Change Holds Notification Phone Number");
+       box.addText("Enter new notification number");
+       box.addNode(et1);
+       box.lines();
+       box.makeGroup([ but, can ]);
+
+       a.onclick = function(){box.show();}
+       return a;
 }
 
 
index 1cebef7..30a839e 100644 (file)
@@ -49,6 +49,10 @@ UserSession.prototype.verifySession = function(ses) {
        else
                this.session_id = this.cookie.fields[UserSession.SES];
 
+       if(this.session_id && this.userObject && this.username && this.connected) {
+               return true;
+       }
+
        if(this.session_id) {
                debug("Retrieveing user info for session " + this.session_id);
 
index 1a2185d..81df9b5 100644 (file)
@@ -706,24 +706,31 @@ function userMessage(msg) {
 
 
 
-/* returns [ xoffset, yoffset ] of the target node */
-function getXYOffsets(target) {
+/* returns [ xoffset, yoffset ] of the target node 
+       object (if provided) is used as the box that will be displayed */
+function getXYOffsets(target, object) {
 
        var x = findPosX(target);
        var y = findPosY(target);
        var height = getObjectHeight(target);
-       var xpos = x;
+       var xpos; 
+
+       if(object) 
+               xpos = x - getObjectWidth(object) + getObjectWidth(target);
+       else xpos = x;
 
        var offsety = y + height;
        var offsetx = xpos; 
        
-       if(IE) { /*HACK XXX*/
+/*
+       if(IE) { 
                offsety = parseInt(offsety) + 15;
                offsetx = parseInt(offsetx) + 8;
        }
+*/
 
        debug("getXYOffset y: " + offsety + " x: " + offsetx );
-       return [x, y];
+       return [offsetx, offsety];
 }
 
 
@@ -737,3 +744,12 @@ function userPressedEnter(evt) {
 }
 
 
+/* return [ x, y ] for the window */
+function getWindowSize() {
+       var doc = getDocument();
+       var win = getWindow();
+       if (IE) 
+               return [doc.body.offsetWidth, doc.body.offsetHeight ];
+       return [        win.innerWidth, win.innerHeight ];
+}
+
diff --git a/Open-ILS/src/javascript/widgets/PopupBox.js b/Open-ILS/src/javascript/widgets/PopupBox.js
new file mode 100644 (file)
index 0000000..b771afa
--- /dev/null
@@ -0,0 +1,104 @@
+/* @target is the object next to which the box should pop up.
+       */
+function PopupBox(target, body) {
+       this.target = target;
+       this.div = elem("div");
+       add_css_class(this.div,"popup_box");
+       add_css_class(this.div,"hide_me");
+       if(body) this.div.appendChild(body);
+       getDocument().body.appendChild(this.div);
+}
+
+PopupBox.prototype.setBody = function(body) {
+       if(body) this.div.appendChild(body);
+}
+
+PopupBox.prototype.addNode = function(node) {
+       if(node) {
+               this.div.appendChild(node);
+               this.lines();
+       }
+}
+
+PopupBox.prototype.addText = function(text) {
+       if(text) {
+               this.div.appendChild(mktext(text));
+               this.lines();
+       }
+}
+
+PopupBox.prototype.lines = function(count) {
+       if(count == null) count = 1;
+       for( var x = 0; x < count; x++ ) {
+               this.div.appendChild(elem("br"));
+       }
+}
+
+PopupBox.prototype.title = function(title) {
+
+       if(title != null) {
+
+               var div = elem("div");
+               add_css_class(div, "popup_box_title");
+               div.appendChild(mktext(title));
+               this.lines();
+
+               if(this.div.firstChild)
+                       this.div.insertBefore(div, this.div.firstChild);
+               else
+                       this.div.appendChild(div);
+       }
+}
+
+
+PopupBox.prototype.show = function() {
+
+       remove_css_class(this.div,"hide_me");
+
+       var A = getXYOffsets(this.target, this.div);
+       var newx = A[0];
+       var newy = A[1];
+
+       var W = getWindowSize();
+       var wx = W[0];
+       var wy = W[1];
+
+
+       var x =  getObjectWidth(this.div);
+       var y =  getObjectHeight(this.div);
+
+       //alert(wx + " : " + wy + " : " + x + " : " + y + " : " + newx + " : " + newy);
+
+       if( (newx + x) > wx )
+               newx = newx - x;
+
+       if( (newy + y) > wy )
+               newy = newy - y - getObjectHeight(this.target);
+
+       this.div.style.left = newx;
+       this.div.style.top = newy;
+
+       add_css_class(this.div,"show_me");
+}
+
+PopupBox.prototype.hide = function() {
+       remove_css_class(this.div,"show_me");
+       add_css_class(this.div,"hide_me");
+}
+
+/* pass in an array of DOM nodes and they will
+       be displayed as a group along the box */
+PopupBox.prototype.makeGroup = function(buttons) {
+
+       var table = elem("table");
+       add_css_class(table, "popup_box_buttons");
+       var row = table.insertRow(0);
+
+       for(var i = 0; i!= buttons.length; i++) {
+               var cell = row.insertCell(row.cells.length);
+               cell.appendChild(buttons[i]);
+       }
+
+       this.div.appendChild(elem("br"));
+       this.div.appendChild(table);
+}