diff --git a/debian/changelog b/debian/changelog index 5611667f..cdc0b788 100644 --- a/debian/changelog +++ b/debian/changelog @@ -52,7 +52,12 @@ hts-tvheadend (2.3) hts; urgency=low from local to nationwide broadcast (AC3 audio is only present in nationwide broadcast) Ticket #78 - + + * Channel editor has been reworked a bit. It uses an editorGrid, similar + to how other grids work in Tvheadend. Tags are mapped inline using + a list-of-values combobox (http://lovcombo.extjs.eu/) + + hts-tvheadend (2.2) hts; urgency=low * Set $HOME so forked processes (XMLTV) will have correct environment diff --git a/src/webui/extjs.c b/src/webui/extjs.c index ecc94a63..177de6ad 100644 --- a/src/webui/extjs.c +++ b/src/webui/extjs.c @@ -270,32 +270,106 @@ extjs_tablemgr(http_connection_t *hc, const char *remain, void *opaque) /** * */ -static int -extjs_chlist(http_connection_t *hc, const char *remain, void *opaque) +static void +extjs_channels_delete(htsmsg_t *in) { - htsbuf_queue_t *hq = &hc->hc_reply; - htsmsg_t *out, *array, *c; + htsmsg_field_t *f; channel_t *ch; - out = htsmsg_create_map(); + TAILQ_FOREACH(f, &in->hm_fields, hmf_link) + if(f->hmf_type == HMF_S64 && + (ch = channel_find_by_identifier(f->hmf_s64)) != NULL) + channel_delete(ch); +} - array = htsmsg_create_list(); - pthread_mutex_lock(&global_lock); +/** + * + */ +static void +extjs_channels_update(htsmsg_t *in) +{ + htsmsg_field_t *f; + channel_t *ch; + htsmsg_t *c; + uint32_t id; + const char *s; - RB_FOREACH(ch, &channel_name_tree, ch_name_link) { - c = htsmsg_create_map(); - htsmsg_add_str(c, "name", ch->ch_name); - htsmsg_add_u32(c, "chid", ch->ch_id); - htsmsg_add_msg(array, NULL, c); + TAILQ_FOREACH(f, &in->hm_fields, hmf_link) { + if((c = htsmsg_get_map_by_field(f)) == NULL || + htsmsg_get_u32(c, "id", &id)) + continue; + + if((ch = channel_find_by_identifier(id)) == NULL) + continue; + + if((s = htsmsg_get_str(c, "name")) != NULL) + channel_rename(ch, s); + + if((s = htsmsg_get_str(c, "xmltvsrc")) != NULL) + channel_set_xmltv_source(ch, xmltv_channel_find_by_displayname(s)); + + if((s = htsmsg_get_str(c, "tags")) != NULL) + channel_set_tags_from_list(ch, s); + } +} + +/** + * + */ +static int +extjs_channels(http_connection_t *hc, const char *remain, void *opaque) +{ + htsbuf_queue_t *hq = &hc->hc_reply; + htsmsg_t *array, *c; + channel_t *ch; + char buf[1024]; + channel_tag_mapping_t *ctm; + const char *op = http_arg_get(&hc->hc_req_args, "op"); + const char *entries = http_arg_get(&hc->hc_req_args, "entries"); + + htsmsg_autodtor(in) = + entries != NULL ? htsmsg_json_deserialize(entries) : NULL; + + htsmsg_autodtor(out) = htsmsg_create_map(); + + scopedgloballock(); + + if(!strcmp(op, "list")) { + array = htsmsg_create_list(); + + RB_FOREACH(ch, &channel_name_tree, ch_name_link) { + c = htsmsg_create_map(); + htsmsg_add_str(c, "name", ch->ch_name); + htsmsg_add_u32(c, "chid", ch->ch_id); + + if(ch->ch_xc != NULL) + htsmsg_add_str(c, "xmltvsrc", ch->ch_xc->xc_displayname); + + buf[0] = 0; + LIST_FOREACH(ctm, &ch->ch_ctms, ctm_channel_link) { + snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), + "%s%d", strlen(buf) == 0 ? "" : ",", + ctm->ctm_tag->ct_identifier); + } + htsmsg_add_str(c, "tags", buf); + + htsmsg_add_msg(array, NULL, c); + } + + htsmsg_add_msg(out, "entries", array); + + } else if(!strcmp(op, "delete") && in != NULL) { + extjs_channels_delete(in); + + } else if(!strcmp(op, "update") && in != NULL) { + extjs_channels_update(in); + + } else { + return 400; } - pthread_mutex_unlock(&global_lock); - - htsmsg_add_msg(out, "entries", array); - htsmsg_json_serialize(out, hq, 0); - htsmsg_destroy(out); http_output_content(hc, "text/x-json; charset=UTF-8"); return 0; } @@ -388,229 +462,6 @@ json_single_record(htsmsg_t *rec, const char *root) } -/** - * - */ -static htsmsg_t * -build_transport_msg(th_transport_t *t) -{ - htsmsg_t *r = htsmsg_create_map(); - th_stream_t *st; - const char *n; - char video[200]; - char audio[200]; - char subtitles[200]; - char scrambling[200]; - - htsmsg_add_u32(r, "enabled", t->tht_enabled); - htsmsg_add_str(r, "name", t->tht_svcname); - - htsmsg_add_str(r, "provider", t->tht_provider ?: ""); - if((n = t->tht_networkname(t)) != NULL) - htsmsg_add_str(r, "network", n); - htsmsg_add_str(r, "source", t->tht_sourcename(t)); - - htsmsg_add_str(r, "status", ""); - - video[0] = 0; - audio[0] = 0; - subtitles[0] = 0; - scrambling[0] = 0; - - LIST_FOREACH(st, &t->tht_components, st_link) { - - switch(st->st_type) { - case SCT_TELETEXT: - case SCT_SUBTITLES: - case SCT_PAT: - case SCT_PMT: - break; - - case SCT_MPEG2VIDEO: - snprintf(video + strlen(video), sizeof(video) - strlen(video), - "%sMPEG-2 (PID:%d", strlen(video) > 0 ? ", " : "", - st->st_pid); - - video: - if(st->st_frame_duration) { - snprintf(video + strlen(video), sizeof(video) - strlen(video), - ", %d Hz)", 90000 / st->st_frame_duration); - } else { - snprintf(video + strlen(video), sizeof(video) - strlen(video), - ")"); - } - - break; - - case SCT_H264: - snprintf(video + strlen(video), sizeof(video) - strlen(video), - "%sH.264 (PID:%d", strlen(video) > 0 ? ", " : "", - st->st_pid); - goto video; - - case SCT_MPEG2AUDIO: - snprintf(audio + strlen(audio), sizeof(audio) - strlen(audio), - "%sMPEG-2 (PID:%d", strlen(audio) > 0 ? ", " : "", - st->st_pid); - audio: - if(st->st_lang[0]) { - snprintf(audio + strlen(audio), sizeof(audio) - strlen(audio), - ", languange: \"%s\")", st->st_lang); - } else { - snprintf(audio + strlen(audio), sizeof(audio) - strlen(audio), - ")"); - } - break; - - case SCT_AC3: - snprintf(audio + strlen(audio), sizeof(audio) - strlen(audio), - "%sAC3 (PID:%d", strlen(audio) > 0 ? ", " : "", - st->st_pid); - goto audio; - - case SCT_AAC: - snprintf(audio + strlen(audio), sizeof(audio) - strlen(audio), - "%sAAC (PID:%d", strlen(audio) > 0 ? ", " : "", - st->st_pid); - goto audio; - - case SCT_CA: - snprintf(scrambling + strlen(scrambling), - sizeof(scrambling) - strlen(scrambling), - "%s%s", strlen(scrambling) > 0 ? ", " : "", - psi_caid2name(st->st_caid)); - break; - } - } - - htsmsg_add_str(r, "video", video); - htsmsg_add_str(r, "audio", audio); - htsmsg_add_str(r, "scrambling", scrambling[0] ? scrambling : "none"); - return r; -} - - -/** - * - */ -static int -extjs_channel(http_connection_t *hc, const char *remain, void *opaque) -{ - htsbuf_queue_t *hq = &hc->hc_reply; - const char *s = http_arg_get(&hc->hc_req_args, "chid"); - const char *op = http_arg_get(&hc->hc_req_args, "op"); - channel_t *ch; - channel_t *ch2; - th_transport_t *t; - int reloadchlist = 0; - htsmsg_t *out, *array, *r; - channel_tag_mapping_t *ctm; - char buf[200]; - - pthread_mutex_lock(&global_lock); - - if(http_access_verify(hc, ACCESS_ADMIN)) { - pthread_mutex_unlock(&global_lock); - return HTTP_STATUS_UNAUTHORIZED; - } - - ch = s ? channel_find_by_identifier(atoi(s)) : NULL; - if(ch == NULL) { - pthread_mutex_unlock(&global_lock); - return HTTP_STATUS_BAD_REQUEST; - } - - if(!strcmp(op, "load")) { - r = htsmsg_create_map(); - htsmsg_add_u32(r, "id", ch->ch_id); - htsmsg_add_str(r, "name", ch->ch_name); - htsmsg_add_str(r, "comdetect", "tt192"); - - if(ch->ch_xc != NULL) - htsmsg_add_str(r, "xmltvchannel", ch->ch_xc->xc_displayname); - - buf[0] = 0; - LIST_FOREACH(ctm, &ch->ch_ctms, ctm_channel_link) { - snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), - "%s%d", strlen(buf) == 0 ? "" : ",", - ctm->ctm_tag->ct_identifier); - } - htsmsg_add_str(r, "tags", buf); - - out = json_single_record(r, "channels"); - - } else if(!strcmp(op, "gettransports")) { - out = htsmsg_create_map(); - array = htsmsg_create_list(); - LIST_FOREACH(t, &ch->ch_transports, tht_ch_link) - htsmsg_add_msg(array, NULL, build_transport_msg(t)); - - htsmsg_add_msg(out, "entries", array); - - } else if(!strcmp(op, "delete")) { - - channel_delete(ch); - - out = htsmsg_create_map(); - htsmsg_add_u32(out, "reloadchlist", 1); - htsmsg_add_u32(out, "success", 1); - - } else if(!strcmp(op, "mergefrom")) { - - if((s = http_arg_get(&hc->hc_req_args, "srcch")) == NULL) - return HTTP_STATUS_BAD_REQUEST; - - ch2 = channel_find_by_identifier(atoi(s)); - if(ch2 == NULL || ch2 == ch) - return HTTP_STATUS_BAD_REQUEST; - - channel_merge(ch, ch2); /* ch2 goes away here */ - - out = htsmsg_create_map(); - htsmsg_add_u32(out, "reloadchlist", 1); - htsmsg_add_u32(out, "success", 1); - - - } else if(!strcmp(op, "save")) { - - if((s = http_arg_get(&hc->hc_req_args, "tags")) != NULL) - channel_set_tags_from_list(ch, s); - - s = http_arg_get(&hc->hc_req_args, "xmltvchannel"); - channel_set_xmltv_source(ch, s?xmltv_channel_find_by_displayname(s):NULL); - - if((s = http_arg_get(&hc->hc_req_args, "name")) != NULL && - strcmp(s, ch->ch_name)) { - - if(channel_rename(ch, s)) { - out = htsmsg_create_map(); - htsmsg_add_u32(out, "success", 0); - htsmsg_add_str(out, "errormsg", "Channel name already exist"); - goto response; - } else { - reloadchlist = 1; - } - } - - out = htsmsg_create_map(); - htsmsg_add_u32(out, "reloadchlist", 1); - htsmsg_add_u32(out, "success", 1); - - } else { - pthread_mutex_unlock(&global_lock); - return HTTP_STATUS_BAD_REQUEST; - } - - response: - pthread_mutex_unlock(&global_lock); - - htsmsg_json_serialize(out, hq, 0); - htsmsg_destroy(out); - - http_output_content(hc, "text/x-json; charset=UTF-8"); - return 0; -} - /** * */ @@ -1528,8 +1379,7 @@ extjs_start(void) http_path_add("/extjs.html", NULL, extjs_root, ACCESS_WEB_INTERFACE); http_path_add("/tablemgr", NULL, extjs_tablemgr, ACCESS_WEB_INTERFACE); http_path_add("/dvbnetworks", NULL, extjs_dvbnetworks, ACCESS_WEB_INTERFACE); - http_path_add("/chlist", NULL, extjs_chlist, ACCESS_WEB_INTERFACE); - http_path_add("/channel", NULL, extjs_channel, ACCESS_WEB_INTERFACE); + http_path_add("/channels", NULL, extjs_channels, ACCESS_WEB_INTERFACE); http_path_add("/xmltv", NULL, extjs_xmltv, ACCESS_WEB_INTERFACE); http_path_add("/channeltags", NULL, extjs_channeltags, ACCESS_WEB_INTERFACE); http_path_add("/epg", NULL, extjs_epg, ACCESS_WEB_INTERFACE); diff --git a/src/webui/static/app/chconf.js b/src/webui/static/app/chconf.js index dfe07822..949830d7 100644 --- a/src/webui/static/app/chconf.js +++ b/src/webui/static/app/chconf.js @@ -8,7 +8,9 @@ tvheadend.channelTags = new Ext.data.JsonStore({ fields: ['identifier', 'name'], id: 'identifier', url:'channeltags', - baseParams: {op: 'listTags'} + baseParams: { + op: 'listTags' + } }); tvheadend.comet.on('channeltags', function(m) { @@ -23,9 +25,12 @@ tvheadend.comet.on('channeltags', function(m) { tvheadend.channels = new Ext.data.JsonStore({ autoLoad: true, root:'entries', - fields: ['name', 'chid'], + fields: ['name', 'chid', 'xmltvsrc', 'tags'], id: 'chid', - url: "chlist" + url: "channels", + baseParams: { + op: 'list' + } }); tvheadend.comet.on('channels', function(m) { @@ -34,343 +39,198 @@ tvheadend.comet.on('channels', function(m) { }); -/** - * Channel details - */ -tvheadend.channeldetails = function(chid, chname) { - var fm = Ext.form; - var xg = Ext.grid; - - var expander = new xg.RowExpander({ - tpl : new Ext.Template( - '
A DnD-enabled version of {@link Ext.DataView}. Drag/drop is implemented by adding - * {@link Ext.data.Record}s to the target DDView. If copying is not being performed, - * the original {@link Ext.data.Record} is removed from the source DDView.
- * @constructor - * Create a new DDView - * @param {Object} config The configuration properties. - */ -Ext.ux.DDView = function(config) { - if (!config.itemSelector) { - var tpl = config.tpl; - if (this.classRe.test(tpl)) { - config.tpl = tpl.replace(this.classRe, 'class=$1x-combo-list-item $2$1'); - } - else { - config.tpl = tpl.replace(this.tagRe, '$1 class="x-combo-list-item" $2'); - } - config.itemSelector = ".x-combo-list-item"; - } - Ext.ux.DDView.superclass.constructor.call(this, Ext.apply(config, { - border: false - })); -}; - -Ext.extend(Ext.ux.DDView, Ext.DataView, { - /** - * @cfg {String/Array} dragGroup The ddgroup name(s) for the View's DragZone (defaults to undefined). - */ - /** - * @cfg {String/Array} dropGroup The ddgroup name(s) for the View's DropZone (defaults to undefined). - */ - /** - * @cfg {Boolean} copy Causes drag operations to copy nodes rather than move (defaults to false). - */ - /** - * @cfg {Boolean} allowCopy Causes ctrl/drag operations to copy nodes rather than move (defaults to false). - */ - /** - * @cfg {String} sortDir Sort direction for the view, 'ASC' or 'DESC' (defaults to 'ASC'). - */ - sortDir: 'ASC', - - // private - isFormField: true, - classRe: /class=(['"])(.*)\1/, - tagRe: /(<\w*)(.*?>)/, - reset: Ext.emptyFn, - clearInvalid: Ext.form.Field.prototype.clearInvalid, - - // private - afterRender: function() { - Ext.ux.DDView.superclass.afterRender.call(this); - if (this.dragGroup) { - this.setDraggable(this.dragGroup.split(",")); - } - if (this.dropGroup) { - this.setDroppable(this.dropGroup.split(",")); - } - if (this.deletable) { - this.setDeletable(); - } - this.isDirtyFlag = false; - this.addEvents( - "drop" - ); - }, - - // private - validate: function() { - return true; - }, - - // private - destroy: function() { - this.purgeListeners(); - this.getEl().removeAllListeners(); - this.getEl().remove(); - if (this.dragZone) { - if (this.dragZone.destroy) { - this.dragZone.destroy(); - } - } - if (this.dropZone) { - if (this.dropZone.destroy) { - this.dropZone.destroy(); - } - } - }, - - /** - * Allows this class to be an Ext.form.Field so it can be found using {@link Ext.form.BasicForm#findField}. - */ - getName: function() { - return this.name; - }, - - /** - * Loads the View from a JSON string representing the Records to put into the Store. - * @param {String} value The JSON string - */ - setValue: function(v) { - if (!this.store) { - throw "DDView.setValue(). DDView must be constructed with a valid Store"; - } - var data = {}; - data[this.store.reader.meta.root] = v ? [].concat(v) : []; - this.store.proxy = new Ext.data.MemoryProxy(data); - this.store.load(); - }, - - /** - * Returns the view's data value as a list of ids. - * @return {String} A parenthesised list of the ids of the Records in the View, e.g. (1,3,8). - */ - getValue: function() { - var result = '('; - this.store.each(function(rec) { - result += rec.id + ','; - }); - return result.substr(0, result.length - 1) + ')'; - }, - - getIds: function() { - var i = 0, result = new Array(this.store.getCount()); - this.store.each(function(rec) { - result[i++] = rec.id; - }); - return result; - }, - - /** - * Returns true if the view's data has changed, else false. - * @return {Boolean} - */ - isDirty: function() { - return this.isDirtyFlag; - }, - - /** - * Part of the Ext.dd.DropZone interface. If no target node is found, the - * whole Element becomes the target, and this causes the drop gesture to append. - */ - getTargetFromEvent : function(e) { - var target = e.getTarget(); - while ((target !== null) && (target.parentNode != this.el.dom)) { - target = target.parentNode; - } - if (!target) { - target = this.el.dom.lastChild || this.el.dom; - } - return target; - }, - - /** - * Create the drag data which consists of an object which has the property "ddel" as - * the drag proxy element. - */ - getDragData : function(e) { - var target = this.findItemFromChild(e.getTarget()); - if(target) { - if (!this.isSelected(target)) { - delete this.ignoreNextClick; - this.onItemClick(target, this.indexOf(target), e); - this.ignoreNextClick = true; - } - var dragData = { - sourceView: this, - viewNodes: [], - records: [], - copy: this.copy || (this.allowCopy && e.ctrlKey) - }; - if (this.getSelectionCount() == 1) { - var i = this.getSelectedIndexes()[0]; - var n = this.getNode(i); - dragData.viewNodes.push(dragData.ddel = n); - dragData.records.push(this.store.getAt(i)); - dragData.repairXY = Ext.fly(n).getXY(); - } else { - dragData.ddel = document.createElement('div'); - dragData.ddel.className = 'multi-proxy'; - this.collectSelection(dragData); - } - return dragData; - } - return false; - }, - - // override the default repairXY. - getRepairXY : function(e){ - return this.dragData.repairXY; - }, - - // private - collectSelection: function(data) { - data.repairXY = Ext.fly(this.getSelectedNodes()[0]).getXY(); - if (this.preserveSelectionOrder === true) { - Ext.each(this.getSelectedIndexes(), function(i) { - var n = this.getNode(i); - var dragNode = n.cloneNode(true); - dragNode.id = Ext.id(); - data.ddel.appendChild(dragNode); - data.records.push(this.store.getAt(i)); - data.viewNodes.push(n); - }, this); - } else { - var i = 0; - this.store.each(function(rec){ - if (this.isSelected(i)) { - var n = this.getNode(i); - var dragNode = n.cloneNode(true); - dragNode.id = Ext.id(); - data.ddel.appendChild(dragNode); - data.records.push(this.store.getAt(i)); - data.viewNodes.push(n); - } - i++; - }, this); - } - }, - - /** - * Specify to which ddGroup items in this DDView may be dragged. - * @param {String} ddGroup The DD group name to assign this view to. - */ - setDraggable: function(ddGroup) { - if (ddGroup instanceof Array) { - Ext.each(ddGroup, this.setDraggable, this); - return; - } - if (this.dragZone) { - this.dragZone.addToGroup(ddGroup); - } else { - this.dragZone = new Ext.dd.DragZone(this.getEl(), { - containerScroll: true, - ddGroup: ddGroup - }); - // Draggability implies selection. DragZone's mousedown selects the element. - if (!this.multiSelect) { this.singleSelect = true; } - - // Wire the DragZone's handlers up to methods in *this* - this.dragZone.getDragData = this.getDragData.createDelegate(this); - this.dragZone.getRepairXY = this.getRepairXY; - this.dragZone.onEndDrag = this.onEndDrag; - } - }, - - /** - * Specify from which ddGroup this DDView accepts drops. - * @param {String} ddGroup The DD group name from which to accept drops. - */ - setDroppable: function(ddGroup) { - if (ddGroup instanceof Array) { - Ext.each(ddGroup, this.setDroppable, this); - return; - } - if (this.dropZone) { - this.dropZone.addToGroup(ddGroup); - } else { - this.dropZone = new Ext.dd.DropZone(this.getEl(), { - owningView: this, - containerScroll: true, - ddGroup: ddGroup - }); - - // Wire the DropZone's handlers up to methods in *this* - this.dropZone.getTargetFromEvent = this.getTargetFromEvent.createDelegate(this); - this.dropZone.onNodeEnter = this.onNodeEnter.createDelegate(this); - this.dropZone.onNodeOver = this.onNodeOver.createDelegate(this); - this.dropZone.onNodeOut = this.onNodeOut.createDelegate(this); - this.dropZone.onNodeDrop = this.onNodeDrop.createDelegate(this); - } - }, - - // private - getDropPoint : function(e, n, dd){ - if (n == this.el.dom) { return "above"; } - var t = Ext.lib.Dom.getY(n), b = t + n.offsetHeight; - var c = t + (b - t) / 2; - var y = Ext.lib.Event.getPageY(e); - if(y <= c) { - return "above"; - }else{ - return "below"; - } - }, - - // private - isValidDropPoint: function(pt, n, data) { - if (!data.viewNodes || (data.viewNodes.length != 1)) { - return true; - } - var d = data.viewNodes[0]; - if (d == n) { - return false; - } - if ((pt == "below") && (n.nextSibling == d)) { - return false; - } - if ((pt == "above") && (n.previousSibling == d)) { - return false; - } - return true; - }, - - // private - onNodeEnter : function(n, dd, e, data){ - if (this.highlightColor && (data.sourceView != this)) { - this.el.highlight(this.highlightColor); - } - return false; - }, - - // private - onNodeOver : function(n, dd, e, data){ - var dragElClass = this.dropNotAllowed; - var pt = this.getDropPoint(e, n, dd); - if (this.isValidDropPoint(pt, n, data)) { - if (this.appendOnly || this.sortField) { - return "x-tree-drop-ok-below"; - } - - // set the insert point style on the target node - if (pt) { - var targetElClass; - if (pt == "above"){ - dragElClass = n.previousSibling ? "x-tree-drop-ok-between" : "x-tree-drop-ok-above"; - targetElClass = "x-view-drag-insert-above"; - } else { - dragElClass = n.nextSibling ? "x-tree-drop-ok-between" : "x-tree-drop-ok-below"; - targetElClass = "x-view-drag-insert-below"; - } - if (this.lastInsertClass != targetElClass){ - Ext.fly(n).replaceClass(this.lastInsertClass, targetElClass); - this.lastInsertClass = targetElClass; - } - } - } - return dragElClass; - }, - - // private - onNodeOut : function(n, dd, e, data){ - this.removeDropIndicators(n); - }, - - // private - onNodeDrop : function(n, dd, e, data){ - if (this.fireEvent("drop", this, n, dd, e, data) === false) { - return false; - } - var pt = this.getDropPoint(e, n, dd); - var insertAt = (this.appendOnly || (n == this.el.dom)) ? this.store.getCount() : n.viewIndex; - if (pt == "below") { - insertAt++; - } - - // Validate if dragging within a DDView - if (data.sourceView == this) { - // If the first element to be inserted below is the target node, remove it - if (pt == "below") { - if (data.viewNodes[0] == n) { - data.viewNodes.shift(); - } - } else { // If the last element to be inserted above is the target node, remove it - if (data.viewNodes[data.viewNodes.length - 1] == n) { - data.viewNodes.pop(); - } - } - - // Nothing to drop... - if (!data.viewNodes.length) { - return false; - } - - // If we are moving DOWN, then because a store.remove() takes place first, - // the insertAt must be decremented. - if (insertAt > this.store.indexOf(data.records[0])) { - insertAt--; - } - } - - // Dragging from a Tree. Use the Tree's recordFromNode function. - if (data.node instanceof Ext.tree.TreeNode) { - var r = data.node.getOwnerTree().recordFromNode(data.node); - if (r) { - data.records = [ r ]; - } - } - - if (!data.records) { - alert("Programming problem. Drag data contained no Records"); - return false; - } - - for (var i = 0; i < data.records.length; i++) { - var r = data.records[i]; - var dup = this.store.getById(r.id); - if (dup && (dd != this.dragZone)) { - if(!this.allowDup && !this.allowTrash){ - Ext.fly(this.getNode(this.store.indexOf(dup))).frame("red", 1); - return true - } - var x=new Ext.data.Record(); - r.id=x.id; - delete x; - } - if (data.copy) { - this.store.insert(insertAt++, r.copy()); - } else { - if (data.sourceView) { - data.sourceView.isDirtyFlag = true; - data.sourceView.store.remove(r); - } - if(!this.allowTrash)this.store.insert(insertAt++, r); - } - if(this.sortField){ - this.store.sort(this.sortField, this.sortDir); - } - this.isDirtyFlag = true; - } - this.dragZone.cachedTarget = null; - return true; - }, - - // private - onEndDrag: function(data, e) { - var d = Ext.get(this.dragData.ddel); - if (d && d.hasClass("multi-proxy")) { - d.remove(); - //delete this.dragData.ddel; - } - }, - - // private - removeDropIndicators : function(n){ - if(n){ - Ext.fly(n).removeClass([ - "x-view-drag-insert-above", - "x-view-drag-insert-left", - "x-view-drag-insert-right", - "x-view-drag-insert-below"]); - this.lastInsertClass = "_noclass"; - } - }, - - /** - * Add a delete option to the DDView's context menu. - * @param {String} imageUrl The URL of the "delete" icon image. - */ - setDeletable: function(imageUrl) { - if (!this.singleSelect && !this.multiSelect) { - this.singleSelect = true; - } - var c = this.getContextMenu(); - this.contextMenu.on("itemclick", function(item) { - switch (item.id) { - case "delete": - this.remove(this.getSelectedIndexes()); - break; - } - }, this); - this.contextMenu.add({ - icon: imageUrl || AU.resolveUrl("/images/delete.gif"), - id: "delete", - text: AU.getMessage("deleteItem") - }); - }, - - /** - * Return the context menu for this DDView. - * @return {Ext.menu.Menu} The context menu - */ - getContextMenu: function() { - if (!this.contextMenu) { - // Create the View's context menu - this.contextMenu = new Ext.menu.Menu({ - id: this.id + "-contextmenu" - }); - this.el.on("contextmenu", this.showContextMenu, this); - } - return this.contextMenu; - }, - - /** - * Disables the view's context menu. - */ - disableContextMenu: function() { - if (this.contextMenu) { - this.el.un("contextmenu", this.showContextMenu, this); - } - }, - - // private - showContextMenu: function(e, item) { - item = this.findItemFromChild(e.getTarget()); - if (item) { - e.stopEvent(); - this.select(this.getNode(item), this.multiSelect && e.ctrlKey, true); - this.contextMenu.showAt(e.getXY()); - } - }, - - /** - * Remove {@link Ext.data.Record}s at the specified indices. - * @param {Array/Number} selectedIndices The index (or Array of indices) of Records to remove. - */ - remove: function(selectedIndices) { - selectedIndices = [].concat(selectedIndices); - for (var i = 0; i < selectedIndices.length; i++) { - var rec = this.store.getAt(selectedIndices[i]); - this.store.remove(rec); - } - }, - - /** - * Double click fires the {@link #dblclick} event. Additionally, if this DDView is draggable, and there is only one other - * related DropZone that is in another DDView, it drops the selected node on that DDView. - */ - onDblClick : function(e){ - var item = this.findItemFromChild(e.getTarget()); - if(item){ - if (this.fireEvent("dblclick", this, this.indexOf(item), item, e) === false) { - return false; - } - if (this.dragGroup) { - var targets = Ext.dd.DragDropMgr.getRelated(this.dragZone, true); - - // Remove instances of this View's DropZone - while (targets.indexOf(this.dropZone) !== -1) { - targets.remove(this.dropZone); - } - - // If there's only one other DropZone, and it is owned by a DDView, then drop it in - if ((targets.length == 1) && (targets[0].owningView)) { - this.dragZone.cachedTarget = null; - var el = Ext.get(targets[0].getEl()); - var box = el.getBox(true); - targets[0].onNodeDrop(el.dom, { - target: el.dom, - xy: [box.x, box.y + box.height - 1] - }, null, this.getDragData(e)); - } - } - } - }, - - // private - onItemClick : function(item, index, e){ - // The DragZone's mousedown->getDragData already handled selection - if (this.ignoreNextClick) { - delete this.ignoreNextClick; - return; - } - - if(this.fireEvent("beforeclick", this, index, item, e) === false){ - return false; - } - if(this.multiSelect || this.singleSelect){ - if(this.multiSelect && e.shiftKey && this.lastSelection){ - this.select(this.getNodes(this.indexOf(this.lastSelection), index), false); - } else if (this.isSelected(item) && e.ctrlKey) { - this.deselect(item); - }else{ - this.deselect(item); - this.select(item, this.multiSelect && e.ctrlKey); - this.lastSelection = item; - } - e.preventDefault(); - } - return true; - } -}); - - - /* * Ext JS Library 2.2 * Copyright(c) 2006-2008, Ext JS, LLC. @@ -1602,4 +998,286 @@ Ext.extend(Ext.ux.grid.RowActions, Ext.util.Observable, { // registre xtype Ext.reg('rowactions', Ext.ux.grid.RowActions); -// eof + +/** + * Ext.ux.form.LovCombo, List of Values Combo + * + * @author Ing. Jozef Sakáloš + * @copyright (c) 2008, by Ing. Jozef Sakáloš + * @date 16. April 2008 + * @version $Id: Ext.ux.form.LovCombo.js 285 2008-06-06 09:22:20Z jozo $ + * + * @license Ext.ux.form.LovCombo.js is licensed under the terms of the Open Source + * LGPL 3.0 license. Commercial use is permitted to the extent that the + * code/component(s) do NOT become part of another Open Source or Commercially + * licensed development library or toolkit without explicit permission. + * + * License details: http://www.gnu.org/licenses/lgpl.html + */ + +/*global Ext */ + +// add RegExp.escape if it has not been already added +if('function' !== typeof RegExp.escape) { + RegExp.escape = function(s) { + if('string' !== typeof s) { + return s; + } + // Note: if pasting from forum, precede ]/\ with backslash manually + return s.replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1'); + }; // eo function escape +} + +// create namespace +Ext.ns('Ext.ux.form'); + +/** + * + * @class Ext.ux.form.LovCombo + * @extends Ext.form.ComboBox + */ +Ext.ux.form.LovCombo = Ext.extend(Ext.form.ComboBox, { + + // {{{ + // configuration options + /** + * @cfg {String} checkField name of field used to store checked state. + * It is automatically added to existing fields. + * Change it only if it collides with your normal field. + */ + checkField:'checked' + + /** + * @cfg {String} separator separator to use between values and texts + */ + ,separator:',' + + /** + * @cfg {String/Array} tpl Template for items. + * Change it only if you know what you are doing. + */ + // }}} + // {{{ + ,initComponent:function() { + + // template with checkbox + if(!this.tpl) { + this.tpl = + '