'libs/jquery',
'libs/underscore',
'libs/text!./templates/main.html',
-'libs/text!./templates/item.html'
-], function($, _, mainTemplate, itemTemplate) {
+'libs/text!./templates/item.html',
+'views/openSelect/openSelect'
+], function($, _, mainTemplate, itemTemplate, OpenSelectView) {
'use strict';
return function(sandbox) {
var currentNode,
- adding = false;
+ adding = false,
+ metadataKeys = (sandbox.getConfig().metadataKeys || [
+ 'author', 'creator', 'date'
+ ]).sort();
var view = {
node: $(_.template(mainTemplate)()),
var newRow = $(_.template(itemTemplate)({key: row.getKey() || '', value: row.getValue() || ''}));
newRow.appendTo(this.metaTable);
newRow.data('row', row);
+
+ var selectView = new OpenSelectView({
+ value: row.getKey() || '',
+ inputTemplate: _.template('<div class="openInput rng-module-metadataEditor-metaItemKey" contentEditable="true"><%= value %></div>')({value: row.getKey() || '' }),
+ setInput: function(inputDOM, value) {
+ inputDOM.text(value);
+ row.setKey(value);
+ }
+ });
+ newRow.find('td:first').append(selectView.el);
+ metadataKeys.forEach(function(key) {
+ selectView.addItem(key);
+ });
+
if(adding) {
$(newRow.find('td div')[0]).focus();
adding = false;
},
updateMetadataRow: function(row) {
this._getRowTr(row, function(tr) {
- var tds = tr.find('td > div'),
+ var tds = tr.find('td [contenteditable]'),
keyTd = $(tds[0]),
valueTd = $(tds[1]);
margin-bottom:10px;
[contenteditable] {
- cursor: pointer;
+ cursor: text;
word-wrap: break-word;
min-height: 13px;
}
border-bottom: none !important;
}
+ tr td {
+ vertical-align: middle;
+ }
+
tr td:nth-child(1){
- width: 20%;
+ width: 30%;
}
tr td:nth-child(2) {
- width:80%;
+ width:70%;
}
tr td:nth-child(3) {
width: 14px;
- vertical-align: middle;
}
}
<tr>
- <td><div contenteditable="true" class="rng-module-metadataEditor-metaItemKey"><%= key %></div></td>
+ <td></td>
<td><div contenteditable="true" class="rng-module-metadataEditor-metaItemValue"><%= value %></div></td>
<td><button class="rng-visualEditor-metaRemoveBtn btn btn-mini btn-danger">x</button></td>
</tr>
\ No newline at end of file
@import 'mixins.less';
@import 'common.less';
+@import '../views/openSelect/openSelect.less';
@import '../modules/data/data.less';
@import '../modules/rng/rng.less';
@import '../modules/documentCanvas/documentCanvas.less';
--- /dev/null
+<li><a tabindex="-1" href="#"><%= value %></a></li>
\ No newline at end of file
--- /dev/null
+define(function(require) {
+
+'use strict';
+
+var _ = require('libs/underscore'),
+ $ = require('libs/jquery'),
+ Backbone = require('libs/backbone'),
+ template = require('libs/text!./template.html'),
+ itemTemplate = require('libs/text!./itemTemplate.html');
+
+
+var OpenSelect = Backbone.View.extend({
+ className: 'openSelect',
+ events: {
+ 'click a': 'onSelection',
+ },
+ initialize: function() {
+ this.$el.css('position', 'relative');
+ this.$el.append(_.template(template)({value: this.options.value || ''}));
+ this.$('.toggle').dropdown();
+ this.menu = this.$('.dropdown-menu');
+ if(this.options.inputTemplate) {
+ this.input = $(this.options.inputTemplate);
+ this.$('.input-wrapper').append(this.input);
+ }
+ },
+ addItem: function(value) {
+ this.menu.append(_.template(itemTemplate)({value: value}));
+ },
+ onSelection: function(e) {
+ var val = $(e.target).text();
+ if(this.options.setInput) {
+ this.options.setInput(this.input, val);
+ }
+ this.trigger('itemSelected', this.input.val());
+ }
+});
+
+return OpenSelect;
+
+});
\ No newline at end of file
--- /dev/null
+.openSelect {
+ @lineHeight: 13px;
+
+ line-height: @lineHeight;
+
+ .toggle-wrapper {
+ width: 1em;
+ :link {
+ text-decoration: none;
+ outline: none;
+ }
+ }
+
+ .input-wrapper {
+ margin: 0;
+ border: 0;
+ padding: 0 0 0 1em;
+ width: calc(~"100% - 1em");
+ margin-top: -@lineHeight;
+ }
+}
\ No newline at end of file
--- /dev/null
+ <div style="position: relative" class="toggle-wrapper">
+ <a class="toggle" href="#">▼</a>
+ <ul class="dropdown-menu"></ul>
+</div>
+<div class="input-wrapper"></div>