| 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <meta http-equiv="Content-type" content="text/html; charset=utf-8"> |
| 5 | <title>MVC DOH Toolbar Widget Test</title> |
| 6 | <style> |
| 7 | @import "../../../../dijit/themes/claro/document.css"; |
| 8 | @import "../../../../dijit/tests/css/dijitTests.css"; |
| 9 | |
| 10 | .flatScreen { |
| 11 | background-image: url(../../../../dijit/tests/images/flatScreen.gif); height: 32px; width: 32px; |
| 12 | </style> |
| 13 | <link id="themeStyles" rel="stylesheet" href="../../../../dijit/themes/claro/claro.css"/> |
| 14 | <script type="text/javascript" data-dojo-config="parseOnLoad:0,isDebug:1,async:1,mvc:{debugBindings:1}" src="../../../../dojo/dojo.js"></script> |
| 15 | |
| 16 | <script type="text/javascript"> |
| 17 | negativeConverter = { |
| 18 | format: function(value){ return !value; }, |
| 19 | parse: function(value){ return !value; } |
| 20 | }; |
| 21 | |
| 22 | require([ |
| 23 | "dojox/mvc", |
| 24 | "dojo/parser", |
| 25 | "dojo/when", |
| 26 | "dojox/mvc/_patches", |
| 27 | "dijit/Declaration", |
| 28 | "dijit/Toolbar", |
| 29 | "dijit/ToolbarSeparator", |
| 30 | "dijit/form/Button", |
| 31 | "dijit/form/DropDownButton", |
| 32 | "dijit/form/ComboButton", |
| 33 | "dijit/form/ToggleButton", |
| 34 | "dijit/ColorPalette", |
| 35 | "dijit/TooltipDialog", |
| 36 | "dijit/form/TextBox", |
| 37 | "dijit/Menu", |
| 38 | "dijit/MenuItem", |
| 39 | "dijit/form/TextBox", |
| 40 | "dijit/form/Select", |
| 41 | "dijit/form/CheckBox" |
| 42 | ], function(mvc, parser, when){ |
| 43 | (cutItemModel = new dojo.Stateful).set("iconClass", "dijitEditorIcon dijitEditorIconCut"); |
| 44 | (copyItemModel = new dojo.Stateful).set("iconClass", "dijitEditorIcon dijitEditorIconCopy").set("label", "Copy"); |
| 45 | boldItemModel = mvc.newStatefulModel({ data : { "checked" : false}}); |
| 46 | require([ |
| 47 | 'doh/runner', 'dijit/dijit' |
| 48 | ], function(){ |
| 49 | require([ |
| 50 | 'dojo/domReady!' |
| 51 | ], function(){ |
| 52 | |
| 53 | doh.register("parse", function() { |
| 54 | var dfd = new doh.Deferred(); |
| 55 | when(dojo.parser.parse(), function(){ |
| 56 | dfd.callback(true); |
| 57 | }); |
| 58 | return dfd; |
| 59 | }); |
| 60 | // should be able to verify all of the inputs |
| 61 | doh.register("check initial values and bindings", [{ |
| 62 | name : "initial", |
| 63 | runTest : function() { |
| 64 | doh.is("Copy", dijit.byId("selCopy").get('value'),"value should be Copy"); |
| 65 | doh.is("Copy", dijit.byId("toolbar1.copy").get('label'),"label should be Copy"); |
| 66 | doh.t(dijit.byId("toolbar1.copy").get('showLabel'),"label should be shown"); |
| 67 | |
| 68 | doh.f(dijit.byId("checkBold").get('checked'),"bold checkbox should be false"); |
| 69 | doh.f(dijit.byId("toolbar1.bold").get('checked'),"bold toolbar should be false"); |
| 70 | |
| 71 | doh.t(dijit.byId("checkItalic").get('checked'),"italic checkbox should be true"); |
| 72 | doh.f(dijit.byId("toolbar1.italic").get('checked'),"italic toolbar should be false"); |
| 73 | } |
| 74 | }]); |
| 75 | |
| 76 | doh.register("update Copy Label", [{ |
| 77 | name : "Update-First-Name", |
| 78 | runTest : function() { |
| 79 | var copyLabel, boldToolbar, bold, italic; |
| 80 | //test first relevant false |
| 81 | copyLabel = dijit.byId("selCopy"); |
| 82 | if (copyLabel) { |
| 83 | copyItemModel.set("label","Copy to clipboard..."); |
| 84 | doh.is("Copy to clipboard...", dijit.byId("selCopy").get('value'),"value should be Copy to clipboard..."); |
| 85 | doh.is("Copy to clipboard...", dijit.byId("toolbar1.copy").get('label'),"label should be Copy to clipboard..."); |
| 86 | } |
| 87 | boldToolbar = dijit.byId("boldtoolbar1.copy"); |
| 88 | if (boldToolbar) { |
| 89 | boldToolbar.set("checked", true); |
| 90 | doh.f(dijit.byId("checkBold").get('checked'),"bold checkbox should be false"); |
| 91 | doh.t(dijit.byId("toolbar1.bold").get('checked'),"bold toolbar should be true"); |
| 92 | } |
| 93 | bold = dijit.byId("checkBold"); |
| 94 | if (bold) { |
| 95 | bold.set("checked",false); |
| 96 | doh.f(dijit.byId("checkBold").get('checked'),"bold checkbox should be false"); |
| 97 | doh.f(dijit.byId("toolbar1.bold").get('checked'),"bold toolbar should be false"); |
| 98 | } |
| 99 | italic = dijit.byId("checkItalic"); |
| 100 | if (italic) { |
| 101 | italic.set("checked",true); |
| 102 | doh.t(dijit.byId("checkItalic").get('checked'),"italic checkbox should be false"); |
| 103 | doh.f(dijit.byId("toolbar1.italic").get('checked'),"italic toolbar should be false"); |
| 104 | } |
| 105 | } |
| 106 | }]); |
| 107 | doh.run(); |
| 108 | |
| 109 | }); |
| 110 | }); |
| 111 | }); |
| 112 | </script> |
| 113 | </head> |
| 114 | |
| 115 | |
| 116 | <body class="claro"> |
| 117 | <script type="dojo/require">at: "dojox/mvc/at"</script> |
| 118 | <h1 class="testTitle">Toolbar test</h1> |
| 119 | |
| 120 | <span data-dojo-type="dijit.Declaration" data-dojo-props='widgetClass:"ToolbarSectionStart", defaults:{ label: "Label"}'> |
| 121 | <span data-dojo-type="dijit.ToolbarSeparator"></span><i>${label}:</i> |
| 122 | </span> |
| 123 | |
| 124 | <h2>Toolbar from markup</h2> |
| 125 | |
| 126 | <div id="toolbar1" data-dojo-type="dijit.Toolbar" |
| 127 | ><div data-dojo-type="ToolbarSectionStart" data-dojo-props='label:"Buttons"'></div |
| 128 | ><div id="toolbar1.cut" data-dojo-type="dijit.form.Button" data-dojo-props='showLabel:false, iconClass: at(cutItemModel, "iconClass")'>Cut</div |
| 129 | ><div id="toolbar1.copy" data-dojo-type="dijit.form.Button" data-dojo-props='showLabel:true, "*": at(copyItemModel, "*")'>Copy</div |
| 130 | |
| 131 | ><div data-dojo-type="ToolbarSectionStart" data-dojo-props='label:"Toggles"'></div |
| 132 | ><div id="toolbar1.bold" data-dojo-type="dijit.form.ToggleButton" data-dojo-props='iconClass:"dijitEditorIcon dijitEditorIconBold", showLabel:false, checked: at(boldItemModel, "checked")'>Bold</div |
| 133 | ><div id="toolbar1.italic" data-dojo-type="dijit.form.ToggleButton" data-dojo-props='iconClass:"dijitEditorIcon dijitEditorIconItalic", showLabel: true'>Italic</div |
| 134 | |
| 135 | ></div> |
| 136 | |
| 137 | <div style="margin-top:8px;"> |
| 138 | Icon for "Cut": |
| 139 | <select data-dojo-type="dijit.form.Select" data-dojo-props="value: at(cutItemModel, 'iconClass')"> |
| 140 | <option value="dijitEditorIcon dijitEditorIconCut">Cut</option> |
| 141 | <option value="dijitFolderClosed">Folder</option> |
| 142 | <option value="noteIcon">Note</option> |
| 143 | <option value="flatScreen">Flat Screen</option> |
| 144 | </select> |
| 145 | </div> |
| 146 | |
| 147 | <div style="margin-top:8px;"> |
| 148 | Icon for "Copy": |
| 149 | <select data-dojo-type="dijit.form.Select" data-dojo-props="value: at(copyItemModel, 'iconClass')"> |
| 150 | <option value="dijitEditorIcon dijitEditorIconCopy">Copy</option> |
| 151 | <option value="dijitFolderClosed">Folder</option> |
| 152 | <option value="noteIcon">Note</option> |
| 153 | <option value="flatScreen">Flat Screen</option> |
| 154 | </select> |
| 155 | </div> |
| 156 | |
| 157 | <div style="margin-top:8px;"> |
| 158 | Label for "Copy": |
| 159 | <select id="selCopy" data-dojo-type="dijit.form.Select" data-dojo-props="value: at(copyItemModel, 'label')"> |
| 160 | <option value="Copy">Copy</option> |
| 161 | <option value="Copy to clipboard...">Copy to clipboard...</option> |
| 162 | </select> |
| 163 | </div> |
| 164 | |
| 165 | <div style="margin-top:8px;"> |
| 166 | Change the state for "Bold" (but this check box is free from change in the tool bar): |
| 167 | <input id="checkBold" data-dojo-type="dijit.form.CheckBox" checked data-dojo-props="checked: at(boldItemModel, 'checked').direction(at.to)"> |
| 168 | </div> |
| 169 | |
| 170 | <div style="margin-top:8px;"> |
| 171 | "Italic" should be unselected (directly bound to the tool bar item widget): |
| 172 | <input id="checkItalic" data-dojo-type="dijit.form.CheckBox" checked data-dojo-props="checked: at(dijit.byId('toolbar1.italic'), 'checked').transform(negativeConverter)"> |
| 173 | </div> |
| 174 | </body> |
| 175 | |
| 176 | </html> |