| 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 | "doh/runner", |
| 24 | "dojo/parser", |
| 25 | "dojo/when", |
| 26 | "dojo/Stateful", |
| 27 | "dojox/mvc/ModelRefController", |
| 28 | "dojox/mvc/_patches", |
| 29 | "dijit/Declaration", |
| 30 | "dijit/Toolbar", |
| 31 | "dijit/ToolbarSeparator", |
| 32 | "dijit/form/Button", |
| 33 | "dijit/form/DropDownButton", |
| 34 | "dijit/form/ComboButton", |
| 35 | "dijit/form/ToggleButton", |
| 36 | "dijit/ColorPalette", |
| 37 | "dijit/TooltipDialog", |
| 38 | "dijit/form/TextBox", |
| 39 | "dijit/Menu", |
| 40 | "dijit/MenuItem", |
| 41 | "dijit/form/TextBox", |
| 42 | "dijit/form/Select", |
| 43 | "dijit/form/CheckBox", |
| 44 | "dojo/domReady!" |
| 45 | ], function(doh, parser, when, Stateful, ModelRefController){ |
| 46 | |
| 47 | cutItemCtrl = new ModelRefController(); |
| 48 | copyItemCtrl = new ModelRefController(); |
| 49 | boldItemCtrl = new ModelRefController(); |
| 50 | |
| 51 | when(parser.parse(), function(){ |
| 52 | cutItemCtrl.set("model", new Stateful({iconClass: "dijitEditorIcon dijitEditorIconCut"})); |
| 53 | copyItemCtrl.set("model", new Stateful({iconClass: "dijitEditorIcon dijitEditorIconCopy", label: "Copy"})); |
| 54 | boldItemCtrl.set("model", new Stateful({checked: false})); |
| 55 | |
| 56 | // should be able to verify all of the inputs |
| 57 | doh.register("check initial values and bindings", [{ |
| 58 | name : "initial", |
| 59 | runTest : function() { |
| 60 | doh.is("Copy", dijit.byId("selCopy").get('value'),"value should be Copy"); |
| 61 | doh.is("Copy", dijit.byId("toolbar1.copy").get('label'),"label should be Copy"); |
| 62 | doh.t(dijit.byId("toolbar1.copy").get('showLabel'),"label should be shown"); |
| 63 | |
| 64 | doh.f(dijit.byId("checkBold").get('checked'),"bold checkbox should be false"); |
| 65 | doh.f(dijit.byId("toolbar1.bold").get('checked'),"bold toolbar should be false"); |
| 66 | |
| 67 | doh.t(dijit.byId("checkItalic").get('checked'),"italic checkbox should be true"); |
| 68 | doh.f(dijit.byId("toolbar1.italic").get('checked'),"italic toolbar should be false"); |
| 69 | } |
| 70 | }]); |
| 71 | |
| 72 | doh.register("update Copy Label", [{ |
| 73 | name : "Update-First-Name", |
| 74 | runTest : function() { |
| 75 | var copyLabel, boldToolbar, bold, italic; |
| 76 | //test first relevant false |
| 77 | copyLabel = dijit.byId("selCopy"); |
| 78 | if (copyLabel) { |
| 79 | copyItemCtrl.set("label","Copy to clipboard..."); |
| 80 | doh.is("Copy to clipboard...", dijit.byId("selCopy").get('value'),"value should be Copy to clipboard..."); |
| 81 | doh.is("Copy to clipboard...", dijit.byId("toolbar1.copy").get('label'),"label should be Copy to clipboard..."); |
| 82 | } |
| 83 | boldToolbar = dijit.byId("boldtoolbar1.copy"); |
| 84 | if (boldToolbar) { |
| 85 | boldToolbar.set("checked", true); |
| 86 | doh.f(dijit.byId("checkBold").get('checked'),"bold checkbox should be false"); |
| 87 | doh.t(dijit.byId("toolbar1.bold").get('checked'),"bold toolbar should be true"); |
| 88 | } |
| 89 | bold = dijit.byId("checkBold"); |
| 90 | if (bold) { |
| 91 | bold.set("checked",false); |
| 92 | doh.f(dijit.byId("checkBold").get('checked'),"bold checkbox should be false"); |
| 93 | doh.f(dijit.byId("toolbar1.bold").get('checked'),"bold toolbar should be false"); |
| 94 | } |
| 95 | italic = dijit.byId("checkItalic"); |
| 96 | if (italic) { |
| 97 | italic.set("checked",true); |
| 98 | doh.t(dijit.byId("checkItalic").get('checked'),"italic checkbox should be false"); |
| 99 | doh.f(dijit.byId("toolbar1.italic").get('checked'),"italic toolbar should be false"); |
| 100 | } |
| 101 | } |
| 102 | }]); |
| 103 | |
| 104 | doh.run(); |
| 105 | }); |
| 106 | }); |
| 107 | </script> |
| 108 | </head> |
| 109 | |
| 110 | <body class="claro"> |
| 111 | <script type="dojo/require">at: "dojox/mvc/at"</script> |
| 112 | <h1 class="testTitle">Toolbar test</h1> |
| 113 | |
| 114 | <span data-dojo-type="dijit.Declaration" data-dojo-props='widgetClass:"ToolbarSectionStart", defaults:{ label: "Label"}'> |
| 115 | <span data-dojo-type="dijit.ToolbarSeparator"></span><i>${label}:</i> |
| 116 | </span> |
| 117 | |
| 118 | <h2>Toolbar from markup</h2> |
| 119 | |
| 120 | <div id="toolbar1" data-dojo-type="dijit.Toolbar" |
| 121 | ><div data-dojo-type="ToolbarSectionStart" data-dojo-props='label:"Buttons"'></div |
| 122 | ><div id="toolbar1.cut" data-dojo-type="dijit.form.Button" data-dojo-props='showLabel:false, iconClass: at(cutItemCtrl, "iconClass")'>Cut</div |
| 123 | ><div id="toolbar1.copy" data-dojo-type="dijit.form.Button" data-dojo-props='showLabel:true, "*": at(copyItemCtrl, "*")'>Copy</div |
| 124 | |
| 125 | ><div data-dojo-type="ToolbarSectionStart" data-dojo-props='label:"Toggles"'></div |
| 126 | ><div id="toolbar1.bold" data-dojo-type="dijit.form.ToggleButton" data-dojo-props='iconClass:"dijitEditorIcon dijitEditorIconBold", showLabel:false, checked: at(boldItemCtrl, "checked")'>Bold</div |
| 127 | ><div id="toolbar1.italic" data-dojo-type="dijit.form.ToggleButton" data-dojo-props='iconClass:"dijitEditorIcon dijitEditorIconItalic", showLabel: true'>Italic</div |
| 128 | |
| 129 | ></div> |
| 130 | |
| 131 | <div style="margin-top:8px;"> |
| 132 | Icon for "Cut": |
| 133 | <select data-dojo-type="dijit.form.Select" data-dojo-props="value: at(cutItemCtrl, 'iconClass')"> |
| 134 | <option value="dijitEditorIcon dijitEditorIconCut">Cut</option> |
| 135 | <option value="dijitFolderClosed">Folder</option> |
| 136 | <option value="noteIcon">Note</option> |
| 137 | <option value="flatScreen">Flat Screen</option> |
| 138 | </select> |
| 139 | </div> |
| 140 | |
| 141 | <div style="margin-top:8px;"> |
| 142 | Icon for "Copy": |
| 143 | <select data-dojo-type="dijit.form.Select" data-dojo-props="value: at(copyItemCtrl, 'iconClass')"> |
| 144 | <option value="dijitEditorIcon dijitEditorIconCopy">Copy</option> |
| 145 | <option value="dijitFolderClosed">Folder</option> |
| 146 | <option value="noteIcon">Note</option> |
| 147 | <option value="flatScreen">Flat Screen</option> |
| 148 | </select> |
| 149 | </div> |
| 150 | |
| 151 | <div style="margin-top:8px;"> |
| 152 | Label for "Copy": |
| 153 | <select id="selCopy" data-dojo-type="dijit.form.Select" data-dojo-props="value: at(copyItemCtrl, 'label')"> |
| 154 | <option value="Copy">Copy</option> |
| 155 | <option value="Copy to clipboard...">Copy to clipboard...</option> |
| 156 | </select> |
| 157 | </div> |
| 158 | |
| 159 | <div style="margin-top:8px;"> |
| 160 | Change the state for "Bold" (but this check box is free from change in the tool bar): |
| 161 | <input id="checkBold" data-dojo-type="dijit.form.CheckBox" checked data-dojo-props="checked: at(boldItemCtrl, 'checked').direction(at.to)"> |
| 162 | </div> |
| 163 | |
| 164 | <div style="margin-top:8px;"> |
| 165 | "Italic" should be unselected (directly bound to the tool bar item widget): |
| 166 | <input id="checkItalic" data-dojo-type="dijit.form.CheckBox" checked data-dojo-props="checked: at(dijit.byId('toolbar1.italic'), 'checked').transform(negativeConverter)"> |
| 167 | </div> |
| 168 | </body> |
| 169 | |
| 170 | </html> |