CCS.Beeswax.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. // Licensed to Cloudera, Inc. under one
  2. // or more contributor license agreements. See the NOTICE file
  3. // distributed with this work for additional information
  4. // regarding copyright ownership. Cloudera, Inc. licenses this file
  5. // to you under the Apache License, Version 2.0 (the
  6. // "License"); you may not use this file except in compliance
  7. // with the License. You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. /*
  17. ---
  18. description: Beeswax (the Hive UI)
  19. provides: [CCS.Beeswax]
  20. requires: [ccs-shared/CCS.JBrowser, clientcide/TabSwapper, More/Form.Validator.Inline, More/Fx.Accordion, ccs-shared/DynamicTextarea, ccs-shared/CCS.PostEditor.Simple, ccs-shared/CCS.JFrame.Chooser]
  21. script: CCS.Beeswax.js
  22. ...
  23. */
  24. ART.Sheet.define('window.beeswax.browser', {
  25. 'min-width': 740
  26. });
  27. ART.Sheet.define('splitview.bw-editor', {
  28. 'right-background-color': '#333'
  29. });
  30. (function(){
  31. CCS.Beeswax = new Class({
  32. Extends: CCS.JBrowser,
  33. options: {
  34. displayHistory: false,
  35. className: 'art beeswax browser logo_header',
  36. height: 350,
  37. jframeOptions: {
  38. clickRelays: 'a, .relays'
  39. }
  40. },
  41. initialize: function(path, options){
  42. this.parent(path || '/beeswax/', options);
  43. this.jframe.addShortcuts({
  44. 'Open Selected': {
  45. keys: 'enter',
  46. shortcut: 'enter',
  47. handler: function(e){
  48. var table = $(this).getElement('[data-filters*=HtmlTable]');
  49. if (!table) return;
  50. hTable = table.retrieve('HtmlTable');
  51. var selected = hTable.selectedRows[0];
  52. if (!selected) return;
  53. CCS.JFrame.doubleClickHandler(this.jframe, selected);
  54. }.bind(this),
  55. description: 'Open the selected item.'
  56. }
  57. });
  58. //linkers for beewswax
  59. this.jframe.addLinkers({
  60. //toggles the display of a group of elements when another is clicked
  61. '[data-group-toggle]': function(event, el) {
  62. /*
  63. get the json data for the toggle
  64. looks like:
  65. {
  66. 'group': '.bw-config-data li', //the elements in the group
  67. 'show':'.bw-serde-options' //the element that you show when you click; all others in the group get hidden
  68. }
  69. See Also: the Collapsible JFrame pattern, which I need to update to work similar to this.
  70. The main diff being that this is about toggling a group; one shows while the others hide.
  71. */
  72. var toggles = JSON.decode(el.get('data-group-toggle'));
  73. var sections = $(this).getElements(toggles.group);
  74. var show = $(this).getElements(toggles.show);
  75. sections.each(function(section) {
  76. section.setStyle('display', show.contains(section) ? 'block' : 'none');
  77. });
  78. }
  79. });
  80. this.jframe.addFilters({
  81. // breadcrumb pattern; has to set z-index programatically for layout
  82. breadcrumb: function(container){
  83. if (!container.get('html').contains('ccs-breadcrumb')) return;
  84. container.getElements('.ccs-breadcrumb').each(function(bc) {
  85. var items = bc.getElements('li');
  86. items.reverse().each(function(item, i){
  87. item.setStyle('z-index', i+1);
  88. });
  89. });
  90. },
  91. //breadcrumb form; displays a breadcrumb that grows as you fill out the form
  92. breadcrumb_form: function(container){
  93. if (!container.get('html').contains('ccs-bc-form')) return;
  94. /*
  95. .ccs-bc-form is a UL with LI items for each breadcrumb; looks like this:
  96. <ul class="ccs-bc-form ccs-breadcrumb clearfix" data-bc-sections=".ccs-bc-section" data-bc-form="form">
  97. <li><a href="#step1">One</a></li>
  98. <li><a href="#step2">Two</a></li>
  99. <li><a href="#step3">Ect</a></li>
  100. </ul>
  101. it has a data-bc-sections definition which is a selector to select the sections that correlate to the bc links
  102. it has a data-bc-form selector that correlates to the form for this bc form.
  103. */
  104. container.getElements('.ccs-bc-form').each(function(bc){
  105. var items = bc.getElements('li');
  106. var form = container.getElement(bc.get('data-bc-form')) || container.getElement('form');
  107. var sections = container.getElements(bc.get('data-bc-sections'));
  108. //extend tab swapper; we need to manage things like OverText and FormValidator when we change sections
  109. var TS = new Class({
  110. Extends: TabSwapper,
  111. showSection: function(index) {
  112. //we validate the form when the user pages forward and not on the first display when this.now is still undefined
  113. //(where this.now is the current index of the TabSwapper; it's undefined on init)
  114. var validate = index > this.now && this.now != undefined;
  115. if (!validate) {
  116. //reset the error state
  117. form.get('validator').reset();
  118. if (this.now != undefined) items[this.now].removeClass('ccs-bc-error');
  119. }
  120. if (!validate || getValidator(form).validate()) {
  121. //show the section if we're valid
  122. this.parent(index);
  123. //show the overtext that might have been hidden
  124. OverText.update();
  125. }
  126. return this;
  127. }
  128. });
  129. //get the form validator and add an event for when elements are validated
  130. //if the element fails, get the nav item and breadcrumb section and add an error class for styling
  131. getValidator(form).addEvents({
  132. elementValidate: function(valid, field){
  133. var section = field.getParent(bc.get('data-bc-sections'));
  134. var nav = items[sections.indexOf(section)];
  135. if (valid) nav.removeClass('ccs-bc-error');
  136. else nav.addClass('ccs-bc-error');
  137. }
  138. });
  139. //create our modified tabswapper
  140. var tabs = new TS({
  141. tabs: items,
  142. sections: sections,
  143. smooth: true
  144. });
  145. //find any sections with an element with the class .ccs-multipart-next and make that
  146. //next button change tabs; note that this is the only way the user can progress forward (for now)
  147. //todo: add some keyboard love; enter, tab, arrows, etc.
  148. sections.each(function(section, i) {
  149. section.getElements('.ccs-multipart-next').addEvent('click', function(e){
  150. e.stop();
  151. if (getValidator(form).validate()) tabs.show(i+1);
  152. });
  153. });
  154. });
  155. },
  156. //displays an input field when the user choose "other" in a select input.
  157. //
  158. // Note that this overwrites the default JFrameFilter because it has extra
  159. // validation logic.
  160. select_with_other: function(container) {
  161. if (!container.get('html').contains('ccs-select-with-other')) return;
  162. container.getElements('.ccs-select-with-other').each(function(el) {
  163. //get the 'other' input
  164. var other = el.getElement('input').set('alt', 'Enter a custom value').addClass('required').addDataFilter('OverText');
  165. //create hint text
  166. var ot = new OverText(other);
  167. //get the select input
  168. var sel = el.getElement('select');
  169. //when the select changes, if the user chooses "other"
  170. //reveal the input, enable the overtext, and enforce validation
  171. sel.addEvent('change', function() {
  172. if (sel.getSelected()[0].get('value') == '__other__') {
  173. other.removeClass('ignoreValidation').reveal().get('reveal').chain(function(){
  174. ot.enable();
  175. });
  176. //else hide and disable the input
  177. } else {
  178. ot.disable();
  179. other.dissolve().addClass('ignoreValidation');
  180. getValidator(el.getParent('form')).validate();
  181. }
  182. });
  183. });
  184. },
  185. dynamic_textarea: function(container) {
  186. if (!container.get('html').contains('ccs-dynamic-textarea')) return;
  187. container.getElements('.ccs-dynamic-textarea').each(function(el){
  188. new DynamicTextarea(el, {
  189. minRows: 5
  190. });
  191. });
  192. },
  193. posteditor: function(container){
  194. if (!container.get('html').contains('ccs-simple-posteditor')) return;
  195. container.getElements('textarea.ccs-simple-posteditor, .ccs-simple-posteditor textarea').each(function(input) {
  196. new CCS.PostEditor.Simple(input);
  197. });
  198. },
  199. accordion: function(container){
  200. if (!container.get('html').contains('accordion')) return;
  201. container.getElements('.accordion').each(function(accordion) {
  202. new Fx.Accordion(accordion.getElements('.toggle'), accordion.getElements('.target'));
  203. });
  204. },
  205. visible: function(container){
  206. if(!container.get('html').contains('ccs-visible')) return;
  207. container.getElements('.ccs-visible').setStyle("display", "");
  208. }
  209. });
  210. this.addEvents({
  211. load: this.setup.bind(this)
  212. });
  213. this.jframe.addEvents({
  214. beforeRenderer: this.stripColumnTemplates.bind(this)
  215. });
  216. },
  217. setup: function(view) {
  218. switch(view) {
  219. case 'table-setup':
  220. this.setupTableForm();
  221. break;
  222. case 'execute':
  223. this.setupEditor();
  224. break;
  225. case 'choose-file':
  226. this.setupChooseFile();
  227. break;
  228. case 'choose-delimiter':
  229. this.setupChooseDelimiter();
  230. break;
  231. case 'define-columns':
  232. this.setupDefineColumns();
  233. break;
  234. }
  235. },
  236. setupChooseFile: function(){
  237. var importData = $(this).getElement('.bw-import_data');
  238. var impLabel = importData.getElement('label');
  239. var impInput = importData.getElement('input');
  240. var checkImportData = function(e){
  241. if (impInput.get('checked')) {
  242. impLabel.removeClass('ccs-bw-selected');
  243. impInput.setProperty('checked', 'false');
  244. } else {
  245. impLabel.addClass('ccs-bw-selected');
  246. impInput.setProperty('checked');
  247. }
  248. };
  249. impLabel.addEvent('click', checkImportData);
  250. if(impInput.get('checked')) impLabel.addClass('ccs-bw-selected');
  251. },
  252. setupDefineColumns: function(){
  253. var showHive = $(this).getElement('.bw-show_hive');
  254. var hiveLabel = showHive.getElement('label');
  255. var hiveInput = showHive.getElement('input');
  256. var checkShowHive = function(e){
  257. if (hiveInput.get('checked')) {
  258. hiveLabel.addClass('ccs-bw-selected');
  259. hiveInput.setProperty('checked', 'false');
  260. } else {
  261. hiveLabel.removeClass('ccs-bw-selected');
  262. hiveInput.setProperty('checked');
  263. }
  264. };
  265. hiveLabel.addEvent('click', checkShowHive);
  266. },
  267. setupChooseDelimiter: function(){
  268. var confirmDelim = $(this).getElement('.bw-confirm_delim');
  269. var selectDelim = $(this).getElement('.bw-select_delim');
  270. if(confirmDelim) {
  271. var yes = confirmDelim.getElement('input[name=Yes]');
  272. var no = confirmDelim.getElement('input[name=No]');
  273. confirmDelim.show();
  274. selectDelim.hide();
  275. no.addEvent('click', function(){
  276. confirmDelim.hide();
  277. selectDelim.show();
  278. });
  279. } else {
  280. selectDelim.show();
  281. }
  282. var otherInput = selectDelim.getElement('input[name=delimiter_1]');
  283. var delimiters = selectDelim.getElement('select[name=delimiter_0]');
  284. delimiters.addEvent('change', function(e){
  285. if(delimiters.getProperty('value') !== '__other__')
  286. {
  287. var form = delimiters.getParent('form');
  288. form.retrieve('form.request').setOptions({
  289. extraData:
  290. {'submit_preview': 'Preview'}
  291. }).send();
  292. }
  293. });
  294. },
  295. setupTableForm: function(){
  296. /* format inputs */
  297. var formatSection = $(this).getElement('.bw-format');
  298. //all the inputs in the format section have custom click behavior
  299. //to add a css class for styling purposes based on their checked state
  300. var checkFormSectionInput = function(input, validate) {
  301. if (input.get('checked')) {
  302. formatSection.getElements('dt').removeClass('ccs-bw-selected');
  303. input.getParent('dt').addClass('ccs-bw-selected');
  304. if (validate) $(this).getElement('form').validate();
  305. }
  306. }.bind(this);
  307. //when the user clicks, check the input and set up classes, validate the form, etc.
  308. formatSection.getElements('input').each(function(input) {
  309. input.addEvent('click', function(){
  310. checkFormSectionInput(input, true);
  311. });
  312. //do this on startup in case the input has a default value
  313. checkFormSectionInput(input);
  314. //if the input is checked, we have to invoke the data-group-toggle manually
  315. //otherwise the next slide shows both the delimited and serde options
  316. if (input.get('checked')) this.jframe.invokeLinker('[data-group-toggle]', input.getParent('[data-group-toggle]'));
  317. }, this);
  318. /* file formats */
  319. var fileSection = $(this).getElement('.bw-file_formats');
  320. var labels = fileSection.getElements('label');
  321. var inputFormatDetails = $(this).getElement('.bw-io_formats');
  322. //fix layout issues; django forces all choice elements to be in a ul
  323. fileSection.getElement('ul').addClass('clearfix');
  324. //private method to retrieve an overtext for an input or create one if there isn't one yet
  325. var getOT = function(input) {
  326. var ot = input.retrieve('OverText');
  327. if (!ot) ot = new OverText(input);
  328. return ot;
  329. };
  330. //get the inputs for the file section
  331. fileSection.getElements('input').each(function(input) {
  332. //whent he user chooses one, add some selected state for styling
  333. input.addEvent('click', function(){
  334. labels.removeClass('ccs-bw-selected');
  335. input.getParent('label').addClass('ccs-bw-selected');
  336. //if the user chooses InputFormat, show the details for that input
  337. //and configure them to be validated
  338. if (input.get('value') == 'InputFormat') {
  339. inputFormatDetails.reveal().get('reveal').chain(function(){
  340. inputFormatDetails.getElements('input').each(function(input){
  341. getOT(input).enable();
  342. input.removeClass('ignoreValidation').addClass('required');
  343. });
  344. });
  345. } else {
  346. //else hide the input format details and disable the validation
  347. inputFormatDetails.dissolve().getElements('input').each(function(input){
  348. getOT(input).disable();
  349. input.addClass('ignoreValidation');
  350. getValidator(input.getParent('form')).validate();
  351. });
  352. }
  353. });
  354. });
  355. /* file location */
  356. var fileLocation = $(this).getElement('.bw-file_location');
  357. var defLabel = fileLocation.getElement('.bw-default_location label');
  358. var fileLoc = fileLocation.getElement('.bw-external_loc');
  359. var fileLocInput = fileLoc.getElement('input').addClass('reqiured');
  360. var input = fileLocation.getElement('.bw-default_location input').set('checked', true);
  361. //private method to toggle style state, validation, and the file location input
  362. var checkFileLoc = function(e){
  363. if (input.get('checked')) {
  364. defLabel.addClass('ccs-bw-selected');
  365. getOT(fileLocInput).disable();
  366. fileLocInput.addClass('ignoreValidation');
  367. fileLoc.dissolve();
  368. //only validate if this was a user-initiated event
  369. if (e) getValidator(input.getParent('form')).validate();
  370. } else {
  371. defLabel.removeClass('ccs-bw-selected');
  372. fileLoc.removeClass('ignoreValidation').reveal().get('reveal').chain(function(){
  373. getOT(fileLocInput).enable();
  374. });
  375. }
  376. };
  377. //check the file state when the user changes the input value
  378. input.addEvent('click', checkFileLoc);
  379. //call it now to set it up.
  380. checkFileLoc();
  381. /* column tables */
  382. var columns = $(this).getElements('div.bw-column');
  383. var columnHeaders = $(this).getElements('.bw-columns dt.bw-column_header');
  384. var columnSections = $(this).getElements('.bw-columns dd.bw-column');
  385. //the column layout is an accordion; starts off with all closed.
  386. this.columnAccordion = new Fx.Accordion(columnHeaders, columnSections, {
  387. onActive: function(toggler, section) {
  388. toggler.addClass('bw-active').removeClass('bw-inactive');
  389. },
  390. onBackground: function(toggler, section) {
  391. toggler.removeClass('bw-active').addClass('bw-inactive');
  392. },
  393. display: -1
  394. });
  395. //create a column form instance for each column form.
  396. columns.each(function(column, i) {
  397. new ColumnForm(column, this.columnAccordion, {
  398. onRemove: this.removeColumn.bind(this)
  399. });
  400. }, this);
  401. //create buttons to add new columns
  402. ['column', 'partition'].each(function(type) {
  403. $(this).getElement('.bw-add_' + type + ' button').addEvent('click', function(e) {
  404. e.stop();
  405. this.addColumn(type, this.columnAccordion);
  406. }.bind(this));
  407. }, this);
  408. },
  409. /*
  410. finds the column templates in the jframe response and removes them before
  411. jframe sets them up like all the other forms
  412. container - (object) see JFrame's beforeRender event
  413. options - (object) ditto
  414. */
  415. stripColumnTemplates: function(container, options){
  416. this.columnTemplates = {};
  417. ['column', 'partition'].each(function(type) {
  418. var el;
  419. container.elements.some(function(section) {
  420. if (!el) el = section.getElement('.beeswax_' + type + '_form_template');
  421. return el;
  422. });
  423. if (el) {
  424. this.columnTemplates[type] = el.get('html');
  425. el.destroy();
  426. }
  427. }, this);
  428. },
  429. /*
  430. adds a new column form
  431. type - either "column" or "partition"
  432. accordion - the accordion that the column is controlled by
  433. */
  434. addColumn: function(type, accordion){
  435. //find the current count
  436. var count_input = $(this).getElement('input[name=' + type +'s-next_form_id]');
  437. //increment it and store it back into the input (as we're adding here)
  438. var count = count_input.get('value').toInt();
  439. count_input.set('value', count + 1);
  440. //create a new column from the template
  441. var column = Elements.from(this.columnTemplates[type].replace("TEMPLATE", count, 'g'))[0];
  442. //store some metadata about it, inject it into the list.
  443. column.store('bw:col-type', type).store('bw:col-count', count);
  444. column.hide().inject($(this).getElement('.bw-' + type + '-forms'));
  445. //apply JFrame magic
  446. this.jframe.applyFilters(column);
  447. //get the header and then add it to the accordion
  448. var columnHeader = column.getElement('dt.bw-column_header');
  449. accordion.addSection(columnHeader, column.getElement('dd.bw-column'));
  450. //expose the new section
  451. column.reveal();
  452. //get the header in that column and, now that it's visible, show its overtext
  453. var input = column.getElement('dt.bw-column_header input');
  454. var ot = input.retrieve('OverText');
  455. if (!ot) ot = new OverText(input);
  456. ot.enable();
  457. //create a new instance of ColumnForm with our new column
  458. new ColumnForm(column, accordion, {
  459. onRemove: this.removeColumn.bind(this)
  460. });
  461. //add the fields in our column to the validator for the form.
  462. getValidator(column.getParent('form')).watchFields(column.getElements('input, textarea, select'));
  463. },
  464. removeColumn: function(column){
  465. column.getElements('input, select, textarea').addClass('ignoreValidation');
  466. column.getParent('form').validate();
  467. column.dissolve();
  468. new Element('input', {
  469. 'type': 'hidden',
  470. 'name': 'columns-' + column.retrieve('bw:col-count') + '-_deleted',
  471. 'value': 'True'
  472. }).inject(column);
  473. },
  474. setupEditor: function(){
  475. //get the editor area, textarea input, & header
  476. var editor = $(this).getElement('.bw-query_bottom');
  477. var ta = editor.getElement('textarea');
  478. //this resizer method resizes the editor area to fill the remaining space below the header
  479. //the shade event is passed true/false if the shade is engaged or not
  480. var resizer = function(){
  481. var header = $(this).getElement('.bw-query_header').getSize().y;
  482. editor.setStyle('height', this.contentSize.y - header - 2);
  483. ta.setStyle('height', this.contentSize.y - header - 2);
  484. }.bind(this);
  485. //do so at startup
  486. resizer();
  487. //and any time the window is resized
  488. this.addEvent('unshade', resizer);
  489. //remove this resize handler on unload
  490. this.jframe.markForCleanup(function(){
  491. this.removeEvent('unshade', resizer);
  492. }.bind(this));
  493. //when the user clicks the save as link, show a popup with the save as form
  494. //when we fire the click manually, it means we want to submit the form
  495. var saveAs = $(this).getElement('.bw-query_save_as');
  496. var saving;
  497. saveAs.addEvent('click', function(e){
  498. //if we aren't trying to submit the form, show the popup
  499. if (!saving) {
  500. //this is the callback for when the user hits the "ok" button
  501. //TODO add some keyboard love for the enter button in fields?
  502. e.stop();
  503. //grab the container of the save as inputs and clone them
  504. //(clone them because our windows destroy themselves on hide)
  505. var saver = $(this).getElement('.bw-query_save_form');
  506. var form = saver.clone();
  507. //prompt the user w/ the form
  508. var prompt = this.prompt('Save This Query', form.show(), function(){
  509. //replace the saver form with the one the user filled out
  510. form.replaces(saver).hide();
  511. //now we're ready to submit the form
  512. saving = true;
  513. //and submit the form
  514. saveAs.click();
  515. //back to showing the popup
  516. saving = false;
  517. });
  518. }
  519. }.bind(this));
  520. //add the settings toggle
  521. var splitEl = $(this).getElement('div[data-filters*=SplitView]');
  522. if (splitEl) {
  523. //get the instance of splitview
  524. var split = splitEl.get('widget');
  525. if (split) {
  526. //let's not show the scrollbar over on the left side
  527. split.left.setStyle('overflow-x', 'hidden');
  528. split.addClass('bw-editor');
  529. //when the user clicks the toggle
  530. $(this).getElement('.bw-query_settings_toggle').addEvent('click', function(e){
  531. e.preventDefault();
  532. //expose or hide the left column
  533. split.chain(resizer).fold('left', split.left.getSize().x > 0 ? 0 : 230);
  534. }.bind(this));
  535. }
  536. }
  537. }
  538. });
  539. //returns an inline form validator for a form or creates one if there isn't one yet
  540. var getValidator = function(form) {
  541. var validator = form.retrieve('validator');
  542. if (!validator) {
  543. validator = new Form.Validator.Inline(form, {
  544. useTitles: true
  545. });
  546. var bwValidateNameRE = /^[a-zA-Z_]\w*/;
  547. validator.add('bw-validate-name', {
  548. errorMsg: 'Please enter a value only containing numbers, letters, underscores - the value cannot begin with a number.',
  549. test: function(element){
  550. return Form.Validator.getValidator('IsEmpty').test(element) ||
  551. (bwValidateNameRE).test(element.get('value'));
  552. }
  553. });
  554. }
  555. return validator;
  556. };
  557. /*
  558. column form class; needed because we add these dynamically
  559. column - the container of the form
  560. header - the header of the section
  561. */
  562. var ColumnForm = new Class({
  563. Implements: [Options, Events],
  564. initialize: function(column, accordion, options) {
  565. this.column = column;
  566. this.header = column.getElement('dt.bw-column_header');
  567. this.accordion = accordion;
  568. this.setOptions(options);
  569. this.setupHeader();
  570. this.setupMapData();
  571. column.getElement('.bw-remove_column button').addEvent('click', function(e){
  572. e.stop();
  573. this.fireEvent('remove', column);
  574. }.bind(this));
  575. },
  576. setupHeader: function(){
  577. //get the header and style it's input behaviors
  578. var input = this.header.getElement('input');
  579. input.addEvents({
  580. focus: function(){
  581. this.header.removeClass('bw-filled');
  582. input.addClass('bw-focused').select();
  583. this.accordion.display(this.accordion.togglers.indexOf(this.header));
  584. }.bind(this),
  585. blur: function(){
  586. if (input.get('value')) this.header.addClass('bw-filled');
  587. else this.header.removeClass('bw-filled');
  588. input.removeClass('bw-focused');
  589. }.bind(this)
  590. });
  591. this.header.getElement('label').addEvents({
  592. mouseover: function(){
  593. input.addClass('bw-focused');
  594. }.bind(this),
  595. mouseleave: function(){
  596. input.removeClass('bw-focused');
  597. }.bind(this)
  598. });
  599. },
  600. setupMapData: function(){
  601. var mapSection = this.column.getElement('.bw-map_data');
  602. if (!mapSection) return; //partition tables don't have these
  603. var arrayTypeSection = this.column.getElement('.bw-array_type');
  604. var typeSelect = this.column.getElement('.bw-col_type select');
  605. var arrayTypeSelect = this.column.getElement('.bw-array_type select');
  606. var checkType = function(){
  607. if (typeSelect.getSelected()[0].get('value') == 'array') arrayTypeSection.fade('in');
  608. else arrayTypeSection.fade('out');
  609. if (typeSelect.getSelected()[0].get('value') == 'map') mapSection.reveal();
  610. else mapSection.dissolve();
  611. };
  612. //for each column table, hide its mapdata config unless the user selects that in the array type
  613. arrayTypeSelect.addEvent('change', checkType.pass(true));
  614. typeSelect.addEvent('change', checkType.pass(true));
  615. checkType();
  616. }
  617. });
  618. })();