Advertisement
Guest User

Untitled

a guest
Oct 30th, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.39 KB | None | 0 0
  1. /*
  2. * Calendar object
  3. */
  4. function cldialogue(cid, objectID) {
  5. this.objectID = objectID;
  6. this.fields = new Array();
  7. this.id = cid;
  8. //this.create_selects ();
  9. this.currentfield = null;
  10. this.showallmaximum = 10;
  11. this.plainfields = new Array(); // input text fields multiple items in a field
  12. this.divpage = null;
  13. }
  14.  
  15. cldialogue.prototype.create_specialfields = function() {
  16. var lmulti = false;
  17. var odiv;
  18. var othis = this;
  19. var ocurdiv, cstyle, ctype;
  20. var npos;
  21.  
  22. $('[data-role="page"]').each(function() { // to trigger page create
  23. othis.divpage = $(this);
  24. });
  25.  
  26. $('[data-type="select_auto"]').each(function() {
  27. ocurdiv = $(this);
  28. lmulti = (ocurdiv.attr("data-multi") == "true");
  29. cfunction = ocurdiv.attr("data-provider");
  30. cfunction = cfunction.replace("()", "('" + ocurdiv.attr("data-id") + "')");
  31. console.log(cfunction);
  32. othis.currentfield = othis.addfield(ocurdiv.attr("data-id"), ocurdiv.attr("data-label"), ocurdiv.attr("data-placeholder"), ocurdiv.attr("data-dbtype"),
  33. lmulti);
  34. othis.currentfield.functioneval = cfunction;
  35. othis.currentfield.parentdiv = ocurdiv;
  36. cstyle = ocurdiv.attr("class");
  37. if (!isnull(cstyle)) {
  38. npos = cstyle.indexOf("hidden");
  39. if (npos == -1) {
  40. eval(cfunction);
  41. }
  42. } else {
  43. eval(cfunction);
  44. }
  45. })
  46.  
  47. //http://localhost:8080/rental/index.php?-action=get_rental_country&objectID=20025"
  48. // insert multiple plain text items
  49. $('[data-type="insert_items"]').each(function() {
  50. ocurdiv = $(this);
  51. cid = ocurdiv.attr("data-id");
  52. cplaceholder = ocurdiv.attr("data-placeholder");
  53. clabel = ocurdiv.attr("data-label");
  54. ctype = ocurdiv.attr("data-dbtype");
  55. ofield = othis.addplainfield(cid, cplaceholder, clabel, ctype, ocurdiv);
  56. })
  57. this.renderplainfields();
  58. this.hidecss();
  59. }
  60.  
  61. cldialogue.prototype.prepare_couple = function(cid) {
  62. var ofield = this.findfield(cid);
  63. var chtml = "";
  64. if (!isnull(ofield)) {
  65. chtml = ofield.prepare_couple();
  66. }
  67. return (chtml);
  68. }
  69.  
  70. cldialogue.prototype.saveplaces = function(cid) {
  71. var ofield = this.findfield(cid);
  72. if (isnull(ofield)) {
  73. ofield = this.findplainfield(cid);
  74. }
  75. if (!isnull(ofield)) {
  76. ofield.saveplacestodb();
  77. } else {
  78. console.log(cid + " not found");
  79. }
  80. }
  81.  
  82. field.prototype.saveplacestodb = function() {
  83. var http = new XMLHttpRequest();
  84. var cstring = "";
  85. var nlen = this.selected.length;
  86. for (var i = 0; i < nlen; i++) {
  87. if (i != 0)
  88. cstring += "_";
  89. cstring += this.selected[i].id;
  90. }
  91. if (cstring != "") {
  92. params = "&type=" + this.type + "&param=" + cstring;
  93. var curl = './index.php?-action=add_asso_place';
  94. var oprocess = genmeta.http_init("saveplaces");
  95.  
  96. http.open("POST", curl, true);
  97.  
  98. //Send the proper header information along with the request
  99. http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  100.  
  101. http.onreadystatechange = function() {//Call a function when the state changes.
  102. if (http.readyState == 4 && http.status == 200) {
  103. JSONresponsehandler(http.responseText, "", "DB Error add places", oprocess.pid);
  104. }
  105. }
  106. http.send(encodeURI(params));
  107. }
  108. }
  109.  
  110. cldialogue.prototype.saveplace_rentalobject = function() {
  111. var http = new XMLHttpRequest();
  112. var countryID = myobject.countryID;
  113. if (countryID == 6) { // france
  114. params = "&countryID=6&regionID=" + myobject.regionID + "&departementID=" + myobject.departementID +
  115. "&placeID=" + myobject.placeID;
  116. } else {
  117. params = "&countryID=" + countryID + "&place=" + encodeURIComponent($("#place").val());
  118. }
  119. params += "&objectID=" + myobject.objectID;
  120. var curl = './index.php?-action=save_place_of_ro';
  121. var oprocess = genmeta.http_init("saveplaces");
  122.  
  123. http.open("POST", curl, true);
  124.  
  125. //Send the proper header information along with the request
  126. http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  127.  
  128. http.onreadystatechange = function() {//Call a function when the state changes.
  129. if (http.readyState == 4 && http.status == 200) {
  130. JSONresponsehandler(http.responseText, "", "DB Error add places", oprocess.pid);
  131. }
  132. }
  133. http.send(encodeURI(params));
  134. }
  135.  
  136. cldialogue.prototype.hidecss = function() {
  137. //.ui-autocomplete { height: 300px; overflow-y: scroll; overflow-x: hidden;}
  138. $('.ui-autocomplete').each(function() {
  139. oel = $(this);
  140. oel.hide();
  141. })
  142. }
  143.  
  144. cldialogue.prototype.renderplainfields = function() {
  145. var nlen = this.plainfields.length;
  146. for (var i = 0; i < nlen; i++) {
  147. ofield = this.plainfields[i];
  148. ofield.render();
  149. }
  150. this.divpage.trigger("create");
  151. }
  152.  
  153. // <div data-type="select_auto" data-multi=true data-placeholder="Kies plaats" data-label="Plaats:" data-id="plaats"></div>
  154. cldialogue.prototype.addplainfield = function(cid, cplaceholder, clabel, ctype, odiv) {
  155. var ofield = new plainfield(this, cid, cplaceholder, clabel, ctype, odiv, this.plainfields.length);
  156. this.plainfields.push(ofield);
  157. return (ofield);
  158. }
  159.  
  160. cldialogue.prototype.getfield = function(cid) {
  161. var ocurfield = odialogue.findfield(cid); // so in case of multiple itmes running on the same place it is always at the correct field
  162. if ((ocurfield != null) && (ocurfield.selected.length == 1)) {
  163. return (ocurfield.selected [0].id);
  164. }
  165. }
  166.  
  167. cldialogue.prototype.findfield = function(cid) {
  168. var nlen = this.fields.length;
  169. for (var i = 0; i < nlen; i++) {
  170. if (this.fields [i].fieldname == cid) {
  171. this.fields[i].data = new Array();
  172. return (this.fields[i])
  173. }
  174. }
  175. }
  176.  
  177. cldialogue.prototype.renderfield = function(cid) {
  178. var nlen = this.fields.length;
  179. for (var i = 0; i < nlen; i++) {
  180. if (this.fields [i].fieldname == cid) {
  181. ofield = this.fields[i];
  182. if ((isnull(ofield.inputfield)) && (!isnull(ofield.functioneval))) {
  183. eval(ofield.functioneval);
  184. if (!isnull(ofield.inputfield)) {
  185. ofield.inputfield.focus();
  186. }
  187. }
  188. return;
  189. }
  190. }
  191. }
  192.  
  193. cldialogue.prototype.eventinput = function(oel) {
  194. var cid = oel.attr("id");
  195. cid = cid.replace("_field", "");
  196. var ofield = odialogue.findfield(cid);
  197. if (!isnull(ofield)) {
  198. if (!ofield.autocomplete_open) {
  199. ofield.prepareautocomplete();
  200. }
  201. }
  202. }
  203.  
  204. cldialogue.prototype.eventblur = function(oel) {
  205. var cid = oel.attr("id");
  206. cid = cid.replace("_field", "");
  207. var ofield = odialogue.findfield(cid);
  208. if (!isnull(ofield)) {
  209. ofield.closeautocomplete();
  210. }
  211. }
  212.  
  213. // <div data-type="select_auto" data-multi=true data-placeholder="Kies plaats" data-label="Plaats:" data-id="plaats"></div>
  214. cldialogue.prototype.addfield = function(cfield, clabel, cplaceholder, ctype, lmulti) {
  215. var ofield = new field(this, cfield, clabel, cplaceholder, ctype, lmulti, this.fields.length);
  216. this.fields.push(ofield);
  217. return (ofield);
  218. }
  219.  
  220. cldialogue.prototype.findplainfield = function(cid) {
  221. var nlen = this.plainfields.length;
  222. for (var i = 0; i < nlen; i++) {
  223. if (this.plainfields[i].id == cid)
  224. return (this.plainfields[i]);
  225. }
  226. }
  227.  
  228. function plainfield(oparent, cid, cplaceholder, clabel, ctype, odiv, nidx) {
  229. if (arguments.length > 0)
  230. this.init(oparent, cid, cplaceholder, clabel, ctype, odiv, nidx);
  231. }
  232.  
  233. plainfield.prototype.init = function(oparent, cid, cplaceholder, clabel, ctype, odiv, nidx) {
  234. this.parent = oparent;
  235. this.id = cid;
  236. this.placeholder = cplaceholder;
  237. this.label = clabel;
  238. this.parentdiv = odiv;
  239. this.type = ctype;
  240. this.idx = nidx;
  241. this.html = "";
  242. this.selected = new Array();
  243. this.fieldname = cid;
  244. }
  245.  
  246. plainfield.prototype.addselection = function(ctext) {
  247. var oselection = new selection(this.selected.length, ctext);
  248. this.selected.push(oselection);
  249. }
  250.  
  251. plainfield.prototype.render = function() {
  252. var chtml = "";
  253. var othis = this;
  254. var cval, oid, ofield, oel;
  255.  
  256. chtml += "<div id='" + this.id + "_field_id' class='divinfo'>&nbsp;<\/div>";
  257. chtml += "<div data-role='fieldcontain' id='fc_" + this.id + "'>";
  258. chtml += "<label for='" + this.id + "'>" + this.label + "<\/label>";
  259. chtml += "<input id='" + this.id + "' placeholder='" + this.placeholder + "' type='text' name='" + this.id + "' value='' >";
  260. chtml += "<\/div>";
  261. this.parentdiv.append(chtml);
  262.  
  263. $("#" + this.id + "_field_id").click(function(event) {
  264. cid = event.target.id;
  265. cid = cid.replace("_field_id", "");
  266. ofield = othis.parent.findplainfield(cid);
  267. if (!isnull(ofield)) {
  268. othis.createselect();
  269. }
  270. });
  271.  
  272. $("#" + this.id).keyup(function(event) {
  273. if (event.keyCode == 13) {
  274. cid = event.target.id;
  275. ofield = othis.parent.findplainfield(cid);
  276. cval = $("#" + this.id).val();
  277. if (!isnull(ofield)) {
  278. oel = $("#" + ofield.id + "_field_id");
  279. othis.addselection(cval);
  280. if (ofield.html == "") {
  281. ofield.html = cval;
  282. oel.html(cval);
  283. } else {
  284. ofield.html += ", " + cval
  285. oel.html(ofield.html);
  286. }
  287. $("#" + this.id).val("");
  288. }
  289. }
  290. });
  291. }
  292.  
  293. // cascade save
  294. plainfield.prototype.saveplacestodb = function() {
  295. this.country = this.parent.getfield("land");
  296. var nlen = this.selected.length;
  297.  
  298. if ((!isnull(this.country)) && (nlen > 0)) {
  299. this.saveentry(0);
  300. }
  301. }
  302.  
  303. // save to place and save to rental_object_places
  304. plainfield.prototype.saveentry = function(idx) {
  305. var http = new XMLHttpRequest();
  306. var cplace = this.selected [idx].selected;
  307. var nlen = this.selected.length;
  308. var params = "&place=" + cplace + "&countryID=" + this.country + "&type=" + this.type;
  309. var curl = './index.php?-action=add_place';
  310. var othis = this;
  311. var oprocess = genmeta.http_init();
  312.  
  313. http.open("POST", curl, true);
  314.  
  315. //Send the proper header information along with the request
  316. http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  317.  
  318. http.onreadystatechange = function() {//Call a function when the state changes.
  319. if (http.readyState == 4 && http.status == 200) {
  320. JSONresponsehandler(http.responseText, "", "DB error email send", oprocess.pid);
  321. if (idx < nlen - 1) {
  322. idx++;
  323. othis.saveentry(idx);
  324. }
  325. }
  326. }
  327. http.send(encodeURI(params));
  328. }
  329.  
  330. function field(oparent, cfield, clabel, cplaceholder, ctype, lmulti, nidx) {
  331. if (arguments.length > 0)
  332. this.init(oparent, cfield, clabel, cplaceholder, ctype, lmulti, nidx);
  333. }
  334.  
  335. field.prototype.init = function(oparent, cfield, clabel, cplaceholder, ctype, lmulti, nidx) {
  336. this.parent = oparent;
  337. this.fieldname = cfield;
  338. this.label = clabel;
  339. this.placeholder = cplaceholder;
  340. this.type = ctype;
  341. this.functioneval = null; // code to activate
  342. this.selected = new Array();
  343. this.idx = nidx;
  344. this.multi = lmulti;
  345. this.data = new Array(); // filled by an eval function
  346. this.itemselected = false; // if selected is true and multi is false then we don't need autocomplete
  347. this.html = "&nbsp;"; // holds selected items
  348. this.functionafterselect = null;
  349. this.autocomplete_open = false;
  350. }
  351.  
  352. field.prototype.addselection = function(cid, cselected) {
  353. var oselection = new selection(cid, cselected, this.selected.length);
  354. this.selected.push(oselection);
  355. return (oselection);
  356. }
  357.  
  358. field.prototype.prepare_couple = function(cfield) {
  359. var chtml = "";
  360. var nlen = this.selected.length;
  361. for (var i = 0; i < nlen; i++) {
  362. chtml += "&key" + i + "=" + this.selected[i].id;
  363. }
  364. return (chtml);
  365. }
  366.  
  367. field.prototype.findselected = function(cid) {
  368. var nlen = this.selected.length;
  369. for (var i = 0; i < nlen; i++) {
  370. if (this.selected[i].id == cid)
  371. return (this.selected[i].selected);
  372. }
  373. }
  374.  
  375. field.prototype.refreshselected = function() {
  376. var oel = $("#" + this.fieldname + "_field_id");
  377. if (oel.length > 0) {
  378. if (this.html != "&nbsp;") {
  379. oel.html(this.html);
  380. oel.show();
  381. }
  382. }
  383. }
  384.  
  385. /*
  386. This code has to be inserted using Chrome Inspect Element
  387. <div data-role="fieldcontain" class="ui-field-contain ui-body ui-br"> // odiv
  388. <label for="name" class="ui-input-text">Text Input:</label> // label
  389. <div class="inlineblock"> // odivinlineblock
  390. <div class="ui-input-text ui-shadow-inset ui-corner-all ui-btn-shadow ui-body-c">
  391. <input type="text" name="name" id="name" value="" class="ui-input-text ui-body-c">
  392. </div>
  393. <a href="#"
  394. data-role="button"
  395. data-icon="plus"
  396. data-iconpos="notext"
  397. data-corners="true"
  398. data-shadow="true"
  399. data-iconshadow="true"
  400. data-wrapperels="span"
  401. data-theme="c"
  402. title=""
  403. class="ui-btn ui-btn-up-c ui-shadow ui-btn-corner-all ui-btn-icon-notext"> // ohrefbutton
  404. <span class="ui-btn-inner">
  405. <span class="ui-btn-text"></span>
  406. <span class="ui-icon ui-icon-plus ui-icon-shadow">&nbsp;</span>
  407. </span> //ospan
  408. </a>
  409. </div>
  410. </div>
  411. */
  412. /*
  413. A select box is creating holding the items already chosen
  414. */
  415. field.prototype.createselect = function() {
  416. var othis = this;
  417. var odivsel = $('<div/>', {"id": this.fieldname + "_select_list", "class": "divinfo"});
  418. odivsel.appendTo(this.parentdiv);
  419. var cname = this.fieldname + "_seldialogue";
  420. chtml = "<select name='" + cname + "' id='" + cname + "' multiple='multiple' data-native-menu='false' tabindex='-1'>" +
  421. "<option>Verwijder keuzes</option>";
  422.  
  423. var nlen = this.selected.length;
  424. for (var i = 0; i < nlen; i++) {
  425. chtml += "<option value='" + this.selected[i].id + "'>" + this.selected[i].selected + "</option>";
  426. }
  427. chtml += "</select>";
  428. odivsel.html(chtml);
  429. var myselect = $("#" + cname);
  430. if (!isnull(myselect)) {
  431. myselect.selectmenu();
  432. myselect.selectmenu("refresh");
  433. $("#" + cname + "-button").click(); // open the selectbox
  434. }
  435.  
  436. odivsel.show();
  437. var newselected = new Array();
  438. //*[@id="rentper-dialog"]/div/div[1]/a/span/span[2]
  439. $("#" + cname + "-listbox a[title='Close']").on("click", function() {
  440. var cval = $("#" + cname).val(); // te verwijderen items
  441. if (isnull(cval)) {
  442. cval = "";
  443. } else if ($.isArray(cval)) {
  444. cval = cval.join(", ");
  445. }
  446.  
  447. for (var i = 0; i < nlen; i++) {
  448. cid = othis.selected[i].id;
  449. npos = cval.indexOf(cid);
  450. if (npos == -1) {
  451. onewsel = new selection(othis.selected[i].id, othis.selected[i].selected, newselected.length);
  452. newselected.push(onewsel);
  453. }
  454. }
  455. othis.selected = newselected;
  456. othis.showselection();
  457. odivsel.hide();
  458. });
  459. //$("#" + this.fieldname + "_seldialogue").focus();
  460. $("#" + this.fieldname + "_seldialogue").click(function(event) {
  461. event.stopPropagation();
  462. // Do something
  463. });
  464. }
  465.  
  466. plainfield.prototype.createselect = field.prototype.createselect;
  467.  
  468. field.prototype.showselection = function() {
  469. var nlen = this.selected.length;
  470. var chtml = "";
  471. for (var i = 0; i < nlen; i++) {
  472. if (i == 0) {
  473. chtml = this.selected[i].selected;
  474. } else {
  475. chtml += ", " + this.selected[i].selected;
  476. }
  477. }
  478. var oel = $("#" + this.fieldname + "_field_id");
  479. oel.html(chtml);
  480. }
  481.  
  482. plainfield.prototype.showselection = field.prototype.showselection;
  483.  
  484. field.prototype.insert_multiselect = function() {
  485. var chtml = "";
  486. var othis = this;
  487. //var odivinlineblock = $('<div/>', { "class" : "inlineblock" } );
  488. //odivinlineblock.appendTo (this.parentdiv);
  489. var odivsel = $('<div/>', {"id": this.fieldname + "_field_id", "class": "divinfo hidden"});
  490. odivsel.click(function() {
  491. othis.createselect();
  492. });
  493. odivsel.html("&nbsp;");
  494. odivsel.appendTo(this.parentdiv);
  495.  
  496. var osel_box = $('<div/>', {"id": this.fieldname + "_dialogue_sellist", "class": "hidden"});
  497. osel_box.appendTo(this.parentdiv);
  498.  
  499. var oparagraph = $("<p/>");
  500. var odivres = $('<div/>', {"id": this.fieldname + "_results_count", "class": "divinfo hidden"});
  501. odivres.html("&nbsp;");
  502. odivres.appendTo(this.parentdiv);
  503. oparagraph.appendTo(this.parentdiv);
  504. var odiv = $('<div/>', {"data-role": "fieldcontain", "class": "ui-field-contain ui-body ui-br"});
  505. odiv.appendTo(this.parentdiv);
  506.  
  507. var label = $("<label>", {"for": this.fieldname, "text": this.label, "class": "ui-input-text"});
  508. label.appendTo(odiv);
  509.  
  510. //var odivinlineblock = $('<div/>', { "class" : "inlineblock" } );
  511. //odivinlineblock.appendTo (odiv);
  512.  
  513. //Create the input element
  514. var odivinputparent = $('<div/>', {"class": "ui-input-text ui-shadow-inset ui-corner-all ui-btn-shadow ui-body-c"});
  515. odivinputparent.appendTo(odiv);
  516.  
  517. var input = $('<input type="text">').attr({id: this.fieldname + "_field", placeholder: this.placeholder,
  518. class: "ui-input-text ui-body-c ui-autocomplete-input selinput", autocomplete: "on"});
  519. input.appendTo(odivinputparent);
  520. this.parentdiv.addClass('borderclass');
  521.  
  522. this.inputfield = input;
  523.  
  524. $("#" + this.fieldname + "_field").focus(function() {
  525. odialogue.eventinput($(this));
  526. });
  527. $("#" + this.fieldname + "_field").keydown(function() {
  528. odialogue.eventinput($(this));
  529. });
  530. $("#" + this.fieldname + "_field").click(function() {
  531. odialogue.eventinput($(this));
  532. });
  533. $("#" + this.fieldname + "_field").blur(function() {
  534. odialogue.eventblur($(this));
  535. });
  536. $("#" + this.fieldname + "_field_id").blur(function() {
  537. odialogue.eventblur($(this));
  538. });
  539.  
  540. $("body").click(function(event) {
  541. oel = $("#" + othis.fieldname + "_select_list");
  542. if (oel.length == 1) {
  543. oel.hide();
  544. }
  545. });
  546.  
  547. var odivautocomplete = $('<div/>', {"id": this.fieldname + "_autocompleteContainer"});
  548. odivautocomplete.appendTo(odiv);
  549.  
  550. odivextra = $('<div/>');
  551. odivextra.html("&nbsp;&nbsp;&nbsp;");
  552. odivextra.appendTo(odiv);
  553. //this.create_autocomplete();
  554. }
  555.  
  556. field.prototype.insert_autocomplete = function(cpostcode) {
  557. this.functionafterselect = cpostcode;
  558. this.insert_multiselect(); // data is loaded
  559. this.refreshselected();
  560. this.parentdiv.show();
  561. if (this.data.length < this.parent.showallmaximum) {
  562. $("#" + this.fieldname + "_field").autocomplete("search", "");
  563. }
  564.  
  565. this.inputfield.focus();
  566. }
  567.  
  568. field.prototype.closeautocomplete = function() {
  569. this.autocomplete_open = false;
  570. //$("#" + this.fieldname + "_field_id").hide();
  571. this.fillinputfield();
  572. if (!isnull(this.functionafterselect)) {
  573. eval(this.functionafterselect);
  574. }
  575. }
  576.  
  577. field.prototype.prepareautocomplete = function() {
  578. if (this.html != "&nbsp;") {
  579. $("#" + this.fieldname + "_field_id").show();
  580. $("#" + this.fieldname + "_field_id").html(this.html);
  581. }
  582. $("#" + this.fieldname + "_field").val("");
  583. }
  584.  
  585. field.prototype.setselected = function(cid, cselected) {
  586. var oselected = this.findselected(cid);
  587. if (isnull(oselected)) { // alrready inserted ?
  588. if (this.multi) {
  589. oel = $("#" + this.fieldname + "_field_id");
  590. if (oel.length > 0) {
  591. this.html = $("#" + this.fieldname + "_field_id").html();
  592. }
  593. if (this.html == "&nbsp;") {
  594. this.html = cselected;
  595. } else {
  596. this.html += ", " + cselected;
  597. }
  598. if (oel.length > 0) {
  599. oel.html(this.html + ' ');
  600. }
  601. this.addselection(cid, cselected);
  602. } else {
  603. this.html = cselected;
  604. oel = $("#" + this.fieldname + "_field_id");
  605. if (oel.length > 0) {
  606. $("#" + this.fieldname + "_field_id").html(cselected);
  607. }
  608. $("#" + this.fieldname + "_field_id").show();
  609. this.selected = new Array();
  610. this.addselection(cid, cselected);
  611. }
  612. }
  613. }
  614.  
  615. field.prototype.fillinputfield = function() {
  616. //var chtml = this.html;
  617. //chtml.replace ("&nbsp;","");
  618. //$("#" + this.fieldname + "_field").val(chtml);
  619. $("#" + this.fieldname + "_field").val("");
  620. }
  621.  
  622. /*
  623. <input type=@@text" id=@@land_field" placeholder=@@Kies land" class=@@ui-input-text ui-body-c ui-autocomplete-input selinput" autocomplete=@@on"
  624. */
  625. //<input id="field" type="text" placeholder="Countries (starting with A)" class="ui-input-text ui-body-c ui-autocomplete-input" autocomplete="off">
  626. //<input type="text" id="plaats_field" placeholder="Kies plaats" name="plaats_field" class="ui-input-text ui-body-c ui-autocomplete-input" autocomplete="off">
  627. function create_autocomplete(cid, curl, populate_list) {
  628. var chtml = "";
  629. var othis = this;
  630. var oel = $("#" + cid);
  631.  
  632. if (!isnull(oel)) {
  633. oel.on("filterablebeforefilter", function(e, data) {
  634. var $ul = $(this),
  635. $input = $(data.input),
  636. value = $input.val(),
  637. html = "";
  638. $ul.html("");
  639. if (value && value.length > 0) {
  640. $ul.html("<li><div class='ui-loader'><span class='ui-icon ui-icon-loading'></span></div></li>");
  641. $ul.show();
  642. //$ul.html("<li></li>");
  643. $ul.listview("refresh");
  644. $.ajax({
  645. url: curl,
  646. dataType: "json",
  647. crossDomain: false,
  648. data: {
  649. q: $input.val(),
  650. }
  651. })
  652. .then(function(response) {
  653. $.each(response, function(i, val) {
  654. val.id = cid;
  655. html += populate_list(val, cid);
  656. });
  657. $ul.addClass("floatright");
  658. $ul.html(html);
  659. $ul.listview("refresh");
  660. $ul.trigger("updatelayout");
  661. });
  662. }
  663. });
  664. }
  665. }
  666.  
  667. function selection(cid, cselected) {
  668. if (arguments.length > 0)
  669. this.init(cid, cselected);
  670. }
  671.  
  672. selection.prototype.init = function(cid, cselected) {
  673. this.id = cid;
  674. this.selected = cselected;
  675. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement