/webapp/java/trunk/ws/apps/webapp/web/resources/yahoo/button/component.js

https://github.com/shanti/olio · JavaScript · 165 lines · 104 code · 21 blank · 40 comment · 32 complexity · 47c84131d5077307279e53dbcfc73b00 MD5 · raw file

  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. // define the namespaces
  19. jmaki.namespace("jmaki.widgets.yahoo.button");
  20. /**
  21. * Yahoo UI Button Widget
  22. * @author Ahmad M. Zawawi <ahmad.zawawi@gmail.com>
  23. * @constructor
  24. * @see http://developer.yahoo.com/yui/button/
  25. */
  26. jmaki.widgets.yahoo.button.Widget = function(wargs) {
  27. var publish = "/yahoo/button";
  28. var self = this;
  29. var button;
  30. var action;
  31. var buttonGroup;
  32. var uuid = wargs.uuid;
  33. var buttonId = uuid + "_btn";
  34. var publishSound = false;
  35. var cfg;
  36. YAHOO.log("buttonId = " + buttonId);
  37. //button default event handlers
  38. this.onClick = function() {
  39. var _action;
  40. if (wargs.value) _action = wargs.value.action;
  41. jmaki.processActions(
  42. { topic : publish,
  43. targetId : 'default',
  44. widgetId : wargs.uuid,
  45. action : _action,
  46. type : 'onClick',
  47. value : cfg.label
  48. }
  49. );
  50. //button, 'default', 'onClick');
  51. if (publishSound) {
  52. jmaki.publish('/jmaki/sound',
  53. {
  54. widgetId :buttonId,
  55. url:wargs.widgetDir + '/audio/click.mp3'
  56. }
  57. );
  58. }
  59. }
  60. this.onChange = function(e) {
  61. jmaki.publish(publish + "/onChange", {id:uuid,
  62. value:{oldValue:e.prevValue,newValue:e.newValue}});
  63. };
  64. //Configuration
  65. cfg = {
  66. name: buttonId,
  67. type: "button",
  68. label: "Click me",
  69. href: "http://ajax.dev.java.net",
  70. checked: false,
  71. val: "",
  72. buttons: [
  73. { label:'One', value:'1'}
  74. ]
  75. };
  76. //read the widget configuration arguments
  77. if (typeof wargs.args != 'undefined') {
  78. //overide topic name if needed
  79. if (typeof wargs.args.topic != 'undefined') {
  80. publish = wargs.args.topic;
  81. }
  82. if (typeof wargs.publishSound != 'undefined') {
  83. publishSound = wargs.args.publishSound;
  84. }
  85. if (typeof wargs.args.val != 'undefined') {
  86. cfg.val = wargs.args.val;
  87. }
  88. if (typeof wargs.args.label != 'undefined') {
  89. cfg.label = wargs.args.label;
  90. }
  91. if (typeof wargs.args.href != 'undefined') {
  92. cfg.href = wargs.args.href;
  93. }
  94. if (typeof wargs.args.container != 'undefined') {
  95. //deprecated argument
  96. jmaki.log("Yahoo button: widget uses deprecated 'container' argument. Simply remove it.");
  97. }
  98. }
  99. if (typeof wargs.value != 'undefined') {
  100. v = wargs.value;
  101. if(typeof v.buttons != 'undefined') {
  102. cfg.buttons = v.buttons;
  103. }
  104. if (wargs.value.action) action=wargs.value.action;
  105. }
  106. if (wargs.publish) publish = wargs.publish;
  107. if (wargs.value && wargs.value.label) cfg.label = wargs.value.label;
  108. if (wargs.value && wargs.value.value) cfg.val = wargs.value.value;
  109. /**
  110. * initialize the button
  111. */
  112. function initButton() {
  113. // Create the button
  114. button = new YAHOO.widget.Button(
  115. buttonId,
  116. {
  117. name: cfg.name,
  118. value: cfg.val,
  119. type: cfg.type,
  120. label: cfg.label,
  121. checked: cfg.checked,
  122. href: cfg.href
  123. }
  124. );
  125. if (wargs.value && wargs.value.action) button.action = wargs.value.action;
  126. button.addListener("click", self.onClick);
  127. }
  128. /**
  129. * Returns the current value of the button
  130. */
  131. this.getVal = function() {
  132. return button.get("value");
  133. };
  134. /**
  135. * Sets the disabled property for a button
  136. */
  137. this.setDisabled = function(disabled) {
  138. if(typeof button != 'undefined') {
  139. button.set("disabled",disabled);
  140. }
  141. };
  142. if (!jmaki.loaded) jmaki.subscribe("/jmaki/runtime/loadComplete",initButton);
  143. else initButton();
  144. };