From ba25a624496a328174411f2d1aaf7d6317b8a0d0 Mon Sep 17 00:00:00 2001 From: Adam Sutton Date: Tue, 9 Jul 2013 18:54:23 +0100 Subject: [PATCH] webui: add support for saving multiple entries directly from idnode grid --- src/webui/extjs.c | 37 ++++++++++++++++++++++++---------- src/webui/static/app/idnode.js | 20 +++++++++++++++++- 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/src/webui/extjs.c b/src/webui/extjs.c index 5cee21ff..42c3ad3a 100644 --- a/src/webui/extjs.c +++ b/src/webui/extjs.c @@ -2175,8 +2175,11 @@ extjs_idnode { htsbuf_queue_t *hq = &hc->hc_reply; int isroot = 0; + htsmsg_t *out = NULL; + idnode_t *node = NULL; const char *uuid = http_arg_get(&hc->hc_req_args, "uuid"); const char *op = http_arg_get(&hc->hc_req_args, "op"); +#if 0 const char *root = http_arg_get(&hc->hc_req_args, "root"); if (uuid == NULL) uuid = http_arg_get(&hc->hc_req_args, "node"); @@ -2186,11 +2189,10 @@ extjs_idnode } if (op == NULL) op = "get"; - htsmsg_t *out = NULL; - idnode_t *node; if(uuid == NULL) return HTTP_STATUS_BAD_REQUEST; +#endif pthread_mutex_lock(&global_lock); @@ -2199,11 +2201,9 @@ extjs_idnode return HTTP_STATUS_UNAUTHORIZED; } +#if 0 node = idnode_find(uuid, NULL); - if (!node) { - pthread_mutex_unlock(&global_lock); - return HTTP_STATUS_BAD_REQUEST; - } +#endif if (!strcmp(op, "get")) { out = htsmsg_create_list(); @@ -2211,11 +2211,26 @@ extjs_idnode htsmsg_add_u32(m, "leaf", idnode_is_leaf(node)); htsmsg_add_msg(out, NULL, m); } else if (!strcmp(op, "save")) { - const char *c = http_arg_get(&hc->hc_req_args, "conf"); - htsmsg_t *conf = htsmsg_json_deserialize(c); - if(conf) { - idnode_update(node, conf); - htsmsg_destroy(conf); + const char *s; + htsmsg_t *conf; + if ((s = http_arg_get(&hc->hc_req_args, "nodes"))) { +printf("s = %s\n", s); + htsmsg_t *nodes = htsmsg_json_deserialize(s); + htsmsg_field_t *f; + if (nodes) { + HTSMSG_FOREACH(f, nodes) { + if (!(conf = htsmsg_get_map_by_field(f))) continue; + if (!(uuid = htsmsg_get_str(conf, "uuid"))) continue; + if (!(node = idnode_find(uuid, NULL))) continue; + idnode_update(node, conf); + } + htsmsg_destroy(nodes); + } + } else if ((s = http_arg_get(&hc->hc_req_args, "conf"))) { + if ((conf = htsmsg_json_deserialize(s))) { + idnode_update(node, conf); + htsmsg_destroy(conf); + } } out = htsmsg_create_map(); } else if (!strcmp(op, "childs")) { diff --git a/src/webui/static/app/idnode.js b/src/webui/static/app/idnode.js index ff5082a9..46d3fb05 100644 --- a/src/webui/static/app/idnode.js +++ b/src/webui/static/app/idnode.js @@ -447,7 +447,25 @@ tvheadend.idnode_grid = function(panel, conf) iconCls : 'save', text : 'Save', disabled : true, - handler : function(){} + handler : function(){ + var mr = store.getModifiedRecords(); + var out = new Array(); + for (var x = 0; x < mr.length; x++) { + v = mr[x].getChanges(); + out[x] = v; + out[x].uuid = mr[x].id; + } + Ext.Ajax.request({ + url : 'api/idnode', + params : { + op : 'save', + nodes : Ext.encode(out) + }, + success : function(d) + { + } + }); + } }); buttons.push(saveBtn); undoBtn = new Ext.Toolbar.Button({