Best Atoum code snippet using field.getEvents
controller.php
Source:controller.php
...40 };41 table.setSorting = function(val) {42 $(table).data('fulltable-sorting', val);43 };44 table.getEvents = function() {45 if ($(table).data('fulltable-events') == null) $(table).data('fulltable-events', {});46 return $(table).data('fulltable-events');47 };48 table.setEvents = function(val) {49 $(table).data('fulltable-events', val);50 };51 var types = {52 "integer":["integer", "number"],53 "decimal":["decimal", "float", "double"],54 "string":["string", "literal"]55 };56 var on = function() {57 return methods['on'].apply(this, arguments);58 };59 var clean = function() {60 return methods['clean'].apply(this, arguments);61 };62 var changeSettings = function() {63 return methods['changeSettings'].apply(this, arguments);64 };65 var drawHeader = function() {66 return methods['drawHeader'].apply(this, arguments);67 };68 var drawBody = function() {69 return methods['drawBody'].apply(this, arguments);70 };71 var draw = function() {72 return methods['draw'].apply(this, arguments);73 };74 var filter = function() {75 return methods['filter'].apply(this, arguments);76 };77 var order = function() {78 return methods['order'].apply(this, arguments);79 };80 var validateRow = function() {81 return methods['validateRow'].apply(this, arguments);82 };83 var addRow = function() {84 return methods['addRow'].apply(this, arguments);85 };86 var editRow = function() {87 return methods['editRow'].apply(this, arguments);88 };89 var removeRow = function() {90 return methods['removeRow'].apply(this, arguments);91 };92 var saveRow = function() {93 return methods['saveRow'].apply(this, arguments);94 };95 var discardRow = function() {96 return methods['discardRow'].apply(this, arguments);97 };98 var checkRow = function() {99 return methods['checkRow'].apply(this, arguments);100 };101 var addSortItem = function(fieldName, fieldSort) {102 var removing_indexes = [];103 for (var index in table.getSorting()) {104 if (!table.getSorting().hasOwnProperty(index)) continue;105 var sortingItem = table.getSorting()[index];106 if (sortingItem.name == fieldName) {107 removing_indexes.push(index);108 }109 }110 removing_indexes = removing_indexes.reverse();111 for (var index in removing_indexes) {112 if (!removing_indexes.hasOwnProperty(index)) continue;113 index = removing_indexes[index];114 table.getSorting().splice(index, 1);115 }116 table.getSorting().push({117 name: fieldName,118 sort: fieldSort119 });120 }121 var getHeaderFromDom = function() {122 // Init headers and field names.123 $(table).find("thead th").each(function(th_index, th) {124 var fieldName = $(th).attr("fulltable-field-name");125 if (fieldName == null) {126 fieldName = (new Date()).getTime()+""+(Math.floor(Math.random()*1e8));127 $(th).attr("fulltable-field-name", fieldName);128 }129 table.getKeys()[th_index] = fieldName;130 });131 };132 var drawRow = function(data, tr) {133 if (typeof data != "object") data = null;134 if (tr == null) {135 tr = $("<tr/>");136 for (var key in table.getKeys()) {137 if (!table.getKeys().hasOwnProperty(key)) continue;138 key = table.getKeys()[key];139 var td = $("<td/>");140 $(td).attr("fulltable-field-name", key);141 $(tr).append($(td));142 }143 }144 var row = {};145 $(tr).children("td").each(function(td_index, td) {146 var key = table.getKeys()[td_index];147 if (key != null) $(td).attr("fulltable-field-name", key);148 var value;149 if (data == null) {150 value = $(td).text();151 } else {152 value = data[key];153 }154 var text = value;155 var fieldData = options.fields[key];156 if (fieldData == null) fieldData = {};157 // TODO: Here must be validation of input type: select, checkbox, if (fieldData.options == "boolean")158 if (fieldData.options != null) {159 text = "";160 var found = false;161 for (var option in fieldData.options) {162 if (!fieldData.options.hasOwnProperty(option)) continue;163 option = fieldData.options[option];164 if (option.value == value) {165 text = option.title;166 found = true;167 break;168 }169 }170 if (!found) value = null;171 }172 row[key] = value;173 $(td).text(text);174 });175 row["__dom"] = $(tr);176 row["__filtered"] = false;177 addSelectionControl(row, "body");178 addEditionControl(row, "body");179 return row;180 };181 var getBodyFromDom = function() {182 $(table).find("tbody tr").each(function(tr_index, tr) {183 table.getRows()[tr_index] = drawRow(null, tr);184 });185 };186 <?php if ($edit === true) { ?>187 var addEditionControl = function(row, type) {188 if (!options.editable) return;189 if (typeof row != "object") return;190 var tr = row["__dom"];191 if (!$(tr).is("tr")) return;192 if ($(tr).find(".fulltable-edition-control").length > 0) return;193 var edition_control = null;194 if ($(tr).parent().is("thead") || type == "head") {195 edition_control = $("<th>", {196 'class':"fulltable-edition-control",197 'text':"Acties"198 });199 }200 if ($(tr).parent().is("tbody") || type == "body") {201 edition_control = $("<td/>", {202 'class':"fulltable-edition-control"203 });204 edition_control.append($("<i/>", {205 'class':"fulltable-edit fas fa-pen pen",206 'text':""207 }).click(function() {208 editRow(row);209 }));210 <?php if ($delete === true) { ?>211 edition_control.append($("<i/>", {212 'class':"fulltable-remove fas fa-trash-alt trash",213 'text':""214 }).click(function() {215 removeRow(row);216 }));217 <?php } //end delete function?>218 edition_control.append($("<i/>", {219 'class':"fulltable-save fas fa-check",220 'text':""221 }).click(function() {222 saveRow(row);223 }));224 edition_control.append($("<i/>", {225 'class':"fulltable-create fa fa-plus plus",226 'text':""227 }).click(function() {228 saveRow(row);229 }));230 edition_control.append($("<i/>", {231 'class':"fulltable-discard fas fa-times",232 'text':""233 }).click(function() {234 discardRow(row);235 }));236 }237 <?php } //end edit function?>238 $(tr).append($(edition_control));239 };240 var addSelectionControl = function(row, type) {241 if (!options.selectable) return;242 if (typeof row != "object") return;243 var tr = row["__dom"];244 if (!$(tr).is("tr")) return;245 if ($(tr).find(".fulltable-selection-control").length > 0) return;246 var selection_control = null;247 if ($(tr).parent().is("thead") || type == "head") {248 selection_control = $("<th>", {249 'class':"fulltable-selection-control"250 });251 }252 if ($(tr).parent().is("tbody") || type == "body") {253 selection_control = $("<td/>", {254 'class':"fulltable-selection-control"255 });256 selection_control.append($("<input/>", {257 'type':"checkbox",258 'class':"checkbox",259 'value':row["__selected"]260 }).change(function() {261 checkRow(row);262 }));263 }264 $(tr).prepend($(selection_control));265 };266 var showRowForm = function(row) {267 for (var fieldName in row) {268 if (!row.hasOwnProperty(fieldName)) continue;269 if (fieldName.indexOf("__") == 0) continue;270 var value = row[fieldName];271 if (value == "") value = null;272 var td = $(row["__dom"]).find("td[fulltable-field-name='" + fieldName + "']");273 $(td).empty();274 var fieldData = options.fields[fieldName];275 if (fieldData == null) fieldData = {};276 var input;277 // TODO: Here must be validation of input type: select, checkbox, if (fieldData.options == "boolean")278 if (fieldData.options != null) {279 input = $("<select>", {280 'disabled':fieldData.disabled281 });282 var optionDom = $("<option>", {283 'disabled':fieldData.mandatory,284 'selected':'selected',285 'text':fieldData.placeholder,286 'value':null287 });288 $(input).append($(optionDom));289 for (var option in fieldData.options) {290 if (!fieldData.options.hasOwnProperty(option)) continue;291 option = fieldData.options[option];292 optionDom = $("<option>", {293 'text':option.title,294 'value':option.value295 });296 $(input).append($(optionDom));297 }298 } else {299 input = $("<input>", {300 'type':"text",301 'placeholder':fieldData.placeholder,302 'disabled':fieldData.disabled303 });304 }305 if (value != null) $(input).val(value);306 $(input).change(function(event) {307 $(event.target).removeClass("invalid");308 });309 $(input).keyup(function(event) {310 $(event.target).removeClass("invalid");311 });312 $(td).append($(input));313 }314 $(row["__dom"]).addClass("fulltable-editing");315 };316 var methods = {317 'on':function(eventName, eventHandler) {318 if (typeof eventName != "string" || typeof eventHandler != "function") return;319 if (eventName != "on" && methods[eventName] != null) {320 table.getEvents()[eventName] = function() {321 eventHandler.apply(this, arguments);322 };323 }324 },325 'clean':function() {326 $(table).find(".fulltable-edition-control, .fulltable-sort, .fulltable-filter").remove();327 $(table).removeClass(function (index, className) {328 return (className.match("/(^|\s)fulltable-\S+/g") || []).join(' ');329 });330 $(table).find("*").removeClass(function (index, className) {331 return (className.match("/(^|\s)fultablle-\S+/g") || []).join(' ');332 });333 var dataKeys = ["fulltable-creating", "fulltable-editing"];334 for (var dataKey in dataKeys) {335 if (!dataKeys.hasOwnProperty(dataKey)) continue;336 $(table).removeData(dataKey);337 $(table).find("*").removeData(dataKey);338 }339 if (typeof table.getEvents().clean == "function") table.getEvents().clean();340 },341 'changeSettings':function(newOptionsPart) {342 if (typeof newOptionsPart != "object") return this;343 for (var key in options) {344 if (!options.hasOwnProperty(key)) continue;345 if (newOptionsPart[key] == null) continue;346 if (key == "fields") {347 var fields = options["fields"]348 var newFields = newOptionsPart["fields"];349 if (typeof newFields != "object") continue;350 for (var newFieldName in newFields) {351 if (!newFields.hasOwnProperty(newFieldName)) continue;352 var newField = newFields[newFieldName];353 if (fields[newFieldName] == null) {354 fields[newFieldName] = newField;355 continue;356 }357 for (var key in newField) {358 if (!newField.hasOwnProperty(key)) continue;359 fields[newFieldName][key] = newFields[newFieldName][key];360 }361 }362 continue;363 }364 options[key] = newOptionsPart[key];365 }366 draw();367 if (typeof table.getEvents().changeSettings == "function") table.getEvents().changeSettings(newOptionsPart, options);368 return this;369 },370 'draw':function() {371 drawHeader();372 drawBody();373 return this;374 },375 'drawHeader':function() {376 // Drawing of header377 $(table).find("thead th:not(.fulltable-edition-control):not(.fulltable-selection-control)").each(function(th_index, th) {378 var fieldName = $(th).attr("fulltable-field-name");379 var apply_order = function(reverse) {380 var fieldSort = 0;381 if ($(th).hasClass("fulltable-asc")) {382 fieldSort = 1;383 } else if ($(th).hasClass("fulltable-desc")) {384 fieldSort = -1;385 }386 if (reverse) fieldSort = -fieldSort;387 addSortItem(fieldName, fieldSort);388 };389 apply_order(false);390 // Insertion of ordenation button.391 $(th).children("i.fulltable-sort").remove();392 if (options.orderable) {393 var fieldData = options.fields[fieldName];394 if (fieldData == null) fieldData = {};395 if (fieldData.orderable == null || fieldData.orderable == true) {396 var sortElement = $("<i/>").addClass("fulltable-sort").addClass("fulltable-sort-asc fas fa-caret-up").text("");397 $(sortElement).click(function(event) {398 apply_order(true);399 order();400 });401 $(th).append(sortElement);402 var sortElement = $("<i/>").addClass("fulltable-sort").addClass("fulltable-sort-desc fas fa-caret-down").text("");403 $(sortElement).click(function(event) {404 apply_order(true);405 order();406 });407 $(th).append(sortElement);408 }409 }410 // Insertion of filtering fields.411 $(th).children("div.fulltable-filter, input.fulltable-filter, select.fulltable-filter").remove();412 if (options.filterable) {413 var fieldData = options.fields[fieldName];414 if (fieldData == null) fieldData = {};415 if (fieldData.filterable == null || fieldData.filterable == true) {416 var filterFieldElement;417 if (fieldData.options != null) {418 filterFieldElement = $("<select>", {419 'class':"fulltable-filter"420 });421 var optionDom = $("<option>", {422 'text':"", // TODO: Implement a placeholder for combo filter.423 'value':null424 });425 $(filterFieldElement).append($(optionDom));426 for (var option in fieldData.options) {427 if (!fieldData.options.hasOwnProperty(option)) continue;428 option = fieldData.options[option];429 optionDom = $("<option>", {430 'text':option.title,431 'value':option.value432 });433 $(filterFieldElement).append($(optionDom));434 }435 } else {436 filterFieldElement = $("<input/>", {437 'class':"fulltable-filter",438 'type':"text",439 'placeholder':"Search"440 });441 }442 var filterSpanWrapper = $("<div>", {443 'class':"fulltable-filter"444 });445 $(th).append(filterSpanWrapper);446 $(filterSpanWrapper).append(filterFieldElement);447 }448 }449 }).removeClass("fulltable-asc").removeClass("fulltable-desc").addClass("fulltable-asc");450 $(table).find("input, select").change(function(event) {451 filter();452 });453 $(table).find("input, select").keyup(function(event) {454 filter();455 });456 // Appending of header for edition controls457 addEditionControl({"__dom":$(table).find("thead tr")}, "head");458 addSelectionControl({"__dom":$(table).find("thead tr")}, "head");459 if (typeof table.getEvents().drawHeader == "function") table.getEvents().drawHeader();460 return this;461 },462 'drawBody':function() {463 $(table).find("tbody tr").detach();464 for (var row in table.getRows()) {465 if (!table.getRows().hasOwnProperty(row)) continue;466 row = table.getRows()[row];467 if ((row["__filtered"] && !row["__creating"]) || row["__removed"]) continue;468 row["__invalidOptionRemoved"] = false;469 for (var fieldName in row) {470 if (!row.hasOwnProperty(fieldName)) continue;471 $(row["__dom"]).find("td[fulltable-field-name='" + fieldName + "']").empty();472 if (row["__creating"] || $(row["__dom"]).data("fulltable-editing")) continue;473 var value = row[fieldName];474 var text = value;475 var fieldData = options.fields[fieldName];476 if (fieldData == null) fieldData = {};477 if (fieldData.options != null) {478 // TODO: Here must be validation of input type: select, checkbox, if (fieldData.options == "boolean")479 var found = false;480 if (value == null) {481 if (!fieldData.mandatory) found = true;482 } else {483 for (var option in fieldData.options) {484 if (!fieldData.options.hasOwnProperty(option)) continue;485 option = fieldData.options[option];486 if (option.value == value) {487 found = true;488 text = option.title;489 break;490 }491 }492 }493 row["__invalidOptionRemoved"] = row["__invalidOptionRemoved"] || !found; // If option is not in option list, this restriction must be activated.494 } else {495 row["__invalidOptionRemoved"] = row["__invalidOptionRemoved"] || false; // If options has been removed from field settings, this restriction must be also removed.496 }497 if (value == null) text = "";498 $(row["__dom"]).find("td[fulltable-field-name='" + fieldName + "']").text(text);499 if (row["__invalidOptionRemoved"]) break;500 }501 if (row["__invalidOptionRemoved"] && !row["__creating"]) continue;502 if ($(row["__dom"]).data("fulltable-editing")) {503 showRowForm(row);504 }505 $(table).find("tbody").append(row["__dom"]);506 }507 if (typeof table.getEvents().drawBody == "function") table.getEvents().drawBody(table.getRows());508 return this;509 },510 'filter':function() {511 for (var row in table.getRows()) {512 if (!table.getRows().hasOwnProperty(row)) continue;513 row = table.getRows()[row];514 if (row["__removed"] == true) {515 $(row["__dom"]).remove();516 continue;517 }518 row["__filtered"] = false;519 $(table).find("tbody").append($(row["__dom"]));520 }521 $(table).find("thead th input.fulltable-filter, thead th select.fulltable-filter").each(function (i, e) {522 var filtering_value = $(e).val();523 var fieldName = $(e).parents("th").first().attr("fulltable-field-name");524 for (var row in table.getRows()) {525 if (!table.getRows().hasOwnProperty(row)) continue;526 row = table.getRows()[row];527 var filtered_value = row[fieldName];528 var filtered = false;529 if ($(row["__dom"]).data("fulltable-editing")) continue;530 var fieldData = options.fields[fieldName];531 if (fieldData == null) fieldData = {};532 // TODO: Here must be validation of input type: select, checkbox, if (fieldData.options == "boolean")533 if (fieldData.options != null) {534 filtered = (filtering_value != null && filtering_value != '' && filtered_value != filtering_value);535 } else {536 if (filtered_value == null) filtered_value = '';537 filtered = (filtering_value != null && filtering_value != '' && filtered_value.toUpperCase().indexOf(filtering_value.toUpperCase()) < 0);538 }539 if (filtered) {540 $(row["__dom"]).detach();541 row["__filtered"] = true;542 }543 }544 });545 if (typeof table.getEvents().filter == "function") table.getEvents().filter();546 order();547 return this;548 },549 'order':function(sorting) {550 var fields = table.getSorting();551 if (Array.isArray(sorting)) {552 sorting = sorting.reverse();553 for (var sortingItem in sorting) {554 if (!sorting.hasOwnProperty(sortingItem)) continue;555 sortingItem = sorting[sortingItem];556 if (sortingItem.name != null && typeof(sortingItem.sort) == "number") {557 addSortItem(sortingItem.name, sortingItem.sort);558 }559 }560 }561 var compareFunction = function(field, order) {562 if (order == null) order = 1;563 var result = function (a, b) {564 if (a["__creating"] == true) return 1;565 if (b["__creating"] == true) return -1;566 if (a == null || b == null) return 0;567 var fieldData = options.fields[field];568 if (fieldData == null) fieldData = {};569 // TODO: Here must be validation of input type: select, checkbox, if (fieldData.options == "boolean")570 if (fieldData.options != null) {571 var foundA = false, foundB = false;572 for (var option in fieldData.options) {573 if (!fieldData.options.hasOwnProperty(option)) continue;574 option = fieldData.options[option];575 if (!foundA && option["value"] == a[field]) {576 a = option["title"];577 foundA = true;578 }579 if (!foundB && option["value"] == b[field]) {580 b = option["title"];581 foundB = true;582 }583 if (foundA && foundB) break;584 }585 } else {586 a = a[field];587 b = b[field];588 }589 if (typeof a == "string") a = a.toUpperCase();590 if (typeof b == "string") b = b.toUpperCase();591 if (a == null || b == null) return 0;592 if (!isNaN(a) && !isNaN(b)) {593 a = Number(a);594 b = Number(b);595 return order*(a - b);596 } else {597 if (a < b)598 return order*(-1);599 else if (a == b)600 return 0;601 else602 return order*(1);603 }604 };605 return result;606 };607 if (!Array.isArray(fields) || fields.length == 0) return this;608 for (var field in fields) {609 if (!fields.hasOwnProperty(field)) continue;610 field = fields[field];611 table.setRows(table.getRows().sort(compareFunction(field.name, field.sort)));612 var head = $(table).find("thead th[fulltable-field-name='" + field.name + "']"); // TODO: Improve saving header in all rows by reference.613 $(head).removeClass("fulltable-asc").removeClass("fulltable-desc");614 if (field.sort >= 0) $(head).addClass("fulltable-asc");615 else $(head).addClass("fulltable-desc");616 }617 drawBody();618 if (typeof table.getEvents().order == "function") table.getEvents().order();619 return this;620 },621 'validateRow':function(row, writeRow) {622 if (typeof row != "object") return this;623 var error = false;624 var errors = [];625 var values = {};626 var texts = {};627 row["__validated_texts"] = texts;628 row["__validated_values"] = values;629 for (var fieldName in row) {630 if (!row.hasOwnProperty(fieldName)) continue;631 var fieldError = false;632 if (fieldName.indexOf("__") == 0) continue;633 var fieldData = options.fields[fieldName] || {};634 var td = $(row["__dom"]).find("td[fulltable-field-name='" + fieldName + "']");635 var value = null;636 var text = null;637 if ($(td).find("input").length > 0) {638 value = $(td).find("input").val();639 text = value;640 } else if ($(td).find("select").length > 0) {641 value = $(td).find("select").val();642 } else {643 text = $(td).text();644 }645 // TODO: Here must be validation of input type: select, checkbox, if (fieldData.options == "boolean")646 if (fieldData.options != null) {647 var found = false;648 for (var option in fieldData.options) {649 if (!fieldData.options.hasOwnProperty(option)) continue;650 option = fieldData.options[option];651 if (option["value"] == value) {652 text = option["title"];653 found = true;654 break;655 } else {656 if (text = "") text = null;657 if (option["value"] == text) {658 value = option["value"];659 text = option["title"];660 found = true;661 break;662 }663 }664 }665 if (!found) {666 value = null;667 }668 }669 if (value == "") value = null;670 // Validations:671 if (value == null && fieldData.mandatory) {672 fieldError = true;673 if (fieldData.errors != null && fieldData.errors.mandatory != null) {674 errors.push(fieldData.errors.mandatory);675 }676 }677 if (value != null && fieldData.type != null) {678 var type = null;679 for (var typeEntry in types) {680 if (!types.hasOwnProperty(typeEntry)) continue;681 var typeNames = types[typeEntry];682 if (typeNames.indexOf(fieldData.type) >= 0) {683 type = typeEntry;684 break;685 }686 }687 switch (type) {688 case "decimal":689 if (isNaN(value)) {690 fieldError = true;691 if (fieldData.errors != null && fieldData.errors.type != null) {692 errors.push(fieldData.errors.type);693 value = null;694 }695 break;696 }697 value = Number(value);698 break;699 case "integer":700 if (isNaN(value)) {701 fieldError = true;702 if (fieldData.errors != null && fieldData.errors.type != null) {703 errors.push(fieldData.errors.type);704 value = null;705 }706 break;707 }708 value = Number(value);709 if (Math.floor(value) != value) {710 fieldError = true;711 if (fieldData.errors != null && fieldData.errors.type != null) {712 errors.push(fieldData.errors.type);713 value = null;714 }715 break;716 }717 break;718 case "string":719 default:720 break;721 }722 } else { $("#melding").hide(); } //dont show melding if information is correct723 if (value != null && typeof fieldData.validator == "function") {724 if (!(fieldData.validator(value, row, table.getRows(), table) === true)) {725 fieldError = true;726 if (fieldData.errors != null && fieldData.errors.validator != null) {727 errors.push(fieldData.errors.validator);728 value = null;729 }730 }731 }732 if (value == null) text = "";733 values[fieldName] = value;734 texts[fieldName] = text;735 if (writeRow == null) writeRow = false;736 if (writeRow) {737 for (var fieldName in values) {738 if (!values.hasOwnProperty(fieldName)) continue;739 if ($(td).find("input, select").length > 0) {740 $(td).find("input, select").val(value);741 } else {742 $(td).empty();743 $(td).text(text);744 }745 }746 }747 if (fieldError) {748 $(td).find("input, select").addClass("invalid");749 error = true;750 }751 }752 if (error) {753 if (typeof table.getEvents().error == "function") table.getEvents().error(errors);754 }755 return !error;756 },757 'addRow':function() {758 if (!options.editable) return this;759 if ($(table).data("fulltable-creating")) return this;760 $(table).data("fulltable-creating", true);761 var row = {};762 var row_index = table.getRows().length;763 table.getRows()[row_index] = row;764 row["__creating"] = true;765 row["__dom"] = $("<tr/>");766 row["__filtering"] = false;767 row["__invalidOptionRemoved"] = false;768 for (var fieldName in table.getKeys()) {769 if (!table.getKeys().hasOwnProperty(fieldName)) continue;770 fieldName = table.getKeys()[fieldName];771 var td = $("<td/>", {772 'fulltable-field-name': fieldName773 });774 $(row["__dom"]).append($(td));775 row[fieldName] = "";776 }777 $(table).children("tbody").append($(row["__dom"]));778 addEditionControl(row, "body");779 addSelectionControl(row, "body");780 $(row["__dom"]).find("td.fulltable-selection-control input[type='checkbox']").prop("disabled", true);781 $(row["__dom"]).data("fulltable-editing", true);782 showRowForm(row);783 $(row["__dom"]).addClass("fulltable-creating");784 if (typeof table.getEvents().addRow == "function") table.getEvents().addRow(row);785 return this;786 },787 'editRow':function(row) {788 if (!options.editable) return this;789 if (typeof row != "object") return this;790 $(row["__dom"]).data("fulltable-editing", true);791 showRowForm(row);792 if (typeof table.getEvents().editRow == "function") table.getEvents().editRow(row);793 if (options.alwaysCreating === true) addRow(); // Here this invocation should not be needed, but it cannot cause problems because method idenpontency.794 return this;795 },796 'removeRow':function(row) {797 if (!options.editable) return this;798 if (typeof row != "object") return this;799 row["__removed"] = true;800 $(row["__dom"]).detach();801 for (var fieldName in row) {802 if (!row.hasOwnProperty(fieldName)) continue;803 if (fieldName.indexOf("__") == 0) continue;804 var value = row[fieldName];805 var td = $(row["__dom"]).find("td[fulltable-field-name='" + fieldName + "']");806 $(td).empty();807 var input = $("<input>", {808 'type':"text",809 'value':value810 });811 $(td).append($(input));812 }813 console.log(row); //todo add ajax remove row814 $.ajax({815 type: 'post',816 url: '<?php echo plugins_url(); ?>/risiriWidget/classes/table/api/tableConnect.php/?remove',817 data: JSON.stringify(row),818 contentType: "application/json; charset=utf-8",819 traditional: true,820 success: function (data) {821 console.log("send remove data to server");822 }823 });824 if (typeof table.getEvents().removeRow == "function") table.getEvents().removeRow(row);825 if (options.alwaysCreating === true) addRow();826 return this;827 },828 'saveRow':function(row) { //addrow829 if (!options.editable) return this;830 if (typeof row != "object") return this;831 if (!validateRow(row)) return this;832 $(row["__dom"]).removeClass("fulltable-editing");833 $(row["__dom"]).data("fulltable-editing", false);834 if (row["__creating"]) {835 $(table).data("fulltable-creating", false);836 $(row["__dom"]).removeClass("fulltable-creating");837 $(row["__dom"]).find("td.fulltable-selection-control input[type='checkbox']").prop("disabled", false);838 row["__creating"] = false;839 }840 console.log(row); //todo add ajax addrow841 var myJsonString= JSON.stringify(row);842 $.ajax({843 url: "<?php echo plugins_url(); ?>/risiriWidget/classes/table/api/tableConnect.php/",844 type: "POST",845 dataType: "json",846 data: myJsonString,847 success: function(result) {848 // continue program849 },850 error: function(log) {851 // handle error852 }853 });854 $.ajax({855 type: 'post',856 url: '<?php echo plugins_url(); ?>/risiriWidget/classes/table/api/tableConnect.php/?add',857 data: JSON.stringify(row),858 contentType: "application/json; charset=utf-8",859 traditional: true,860 success: function (data) {861 console.log("send remove data to server");862 }863 });864 for (var fieldName in row) {865 if (!row.hasOwnProperty(fieldName)) continue;866 if (fieldName.indexOf("__") == 0) continue;867 var td = $(row["__dom"]).find("td[fulltable-field-name='" + fieldName + "']");868 $(td).empty();869 $(td).text(row["__validated_texts"][fieldName]);870 row[fieldName] = row["__validated_values"][fieldName];871 }872 if (typeof table.getEvents().saveRow == "function") table.getEvents().saveRow(row);873 if (options.alwaysCreating === true) addRow();874 return this;875 },876 'discardRow': function(row) {877 if (!options.editable) return this;878 if (typeof row != "object") return this;879 $(row["__dom"]).data("fulltable-editing", false);880 $(row["__dom"]).removeClass("fulltable-editing");881 if (row["__creating"]) {882 $(table).data("fulltable-creating", false);883 row["__creating"] = false;884 row["__removed"] = true;885 $(row["__dom"]).detach();886 } else {887 for (var fieldName in row) {888 if (!row.hasOwnProperty(fieldName)) continue;889 if (fieldName.indexOf("__") == 0) continue;890 var value = row[fieldName];891 var text = value;892 if (text == null) text = "";893 var fieldData = options.fields[fieldName] || {};894 // TODO: Here must be validation of input type: select, checkbox, if (fieldData.options == "boolean")895 if (fieldData.options != null) {896 text = "";897 for (var option in fieldData.options) {898 if (!fieldData.options.hasOwnProperty(option)) continue;899 option = fieldData.options[option];900 if (option["value"] == value) {901 text = option["title"];902 break;903 }904 }905 }906 var td = $(row["__dom"]).find("td[fulltable-field-name='" + fieldName + "']");907 $(td).empty();908 $(td).text(text);909 }910 }911 if (typeof table.getEvents().discardRow == "function") table.getEvents().discardRow(row);912 if (options.alwaysCreating === true) addRow();913 return this;914 },915 'checkRow': function(row) {916 if (row["__selected"] == null) row["__selected"] = false;917 row["__selected"] = !row["__selected"];918 if (typeof table.getEvents().checkRow == "function") table.getEvents().checkRow(row);919 },920 'getData':function(selected) {921 var result = [];922 for (var row in table.getRows()) {923 if (!table.getRows().hasOwnProperty(row)) continue;924 row = table.getRows()[row];925 if (row["__selected"] == null) row["__selected"] = false;926 if (selected === false && row["__selected"] == true) continue;927 if (selected === true && row["__selected"] == false) continue;928 var resultRow = {};929 if (row["__creating"] === true) continue;930 if (row["__removed"] === true || row["__invalidOptionRemoved"] === true) continue;931 result.push(resultRow);932 for (var fieldName in row) {933 if (!row.hasOwnProperty(fieldName)) continue;934 if (fieldName.indexOf("__") == 0) continue;935 var value = row[fieldName];936 resultRow[fieldName] = value;937 }938 }939 if (typeof table.getEvents().getData == "function") table.getEvents().getData();940 return result;941 },942 'setData':function(data) {943 if (!Array.isArray(data)) {944 return this;945 }946 var oldData = table.getRows().splice(0, table.getRows().length);947 var newData = data;948 for (var rowData in data) {949 if (!data.hasOwnProperty(rowData)) continue;950 rowData = data[rowData];951 var row = drawRow(rowData, null);952 if (!validateRow(row)) continue;953 table.getRows().push(row);954 }955 drawBody();956 if (typeof table.getEvents().setData == "function") table.getEvents().setData(oldData, newData);957 return this;958 },959 'error': function() {960 return this;961 }962 };963 // DEPRECATED: Compatibility, uncomment if needed964 /*965 methods['create'] = methods['addRow'];966 methods['edit'] = methods['editRow'];967 methods['remove'] = methods['removeRow'];968 methods['save'] = methods['saveRow'];969 methods['discard'] = methods['discardRow'];970 methods['getValue'] = methods['getData'];...
FactoryTest.php
Source:FactoryTest.php
...81 $this->assertEquals($o1->getConfig()->__toArray(), $o2->getConfig()->__toArray());82 }83 public function testGetEventsGrid()84 {85 $this->assertTrue(\Ext_Factory::getEvents('Ext_Grid') instanceof \Ext_Events_Grid);86 $this->assertTrue(\Ext_Factory::getEvents('Grid') instanceof \Ext_Events_Grid);87 $this->assertTrue(\Ext_Factory::getEvents('Grid_Column') instanceof \Ext_Events_Grid_Column);88 $this->assertTrue(\Ext_Factory::getEvents('Grid_Column_Action') instanceof \Ext_Events_Grid_Column_Action);89 $this->assertTrue(\Ext_Factory::getEvents('Grid_Column_Date') instanceof \Ext_Events_Grid_Column_Date);90 $this->assertTrue(\Ext_Factory::getEvents('Grid_Column_Boolean') instanceof \Ext_Events_Grid_Column_Boolean);91 $this->assertTrue(\Ext_Factory::getEvents('Grid_Column_Number') instanceof \Ext_Events_Grid_Column_Number);92 $this->assertTrue(\Ext_Factory::getEvents('Grid_Column_Template') instanceof \Ext_Events_Grid_Column_Template);93 }94 public function testGetEventsComponents()95 {96 //$this->assertTrue(\Ext_Factory::getEvents('Ext_Component_Filter') instanceof \Ext_Events_Component_Filter);97 //$this->assertTrue(\Ext_Factory::getEvents('Component_Field_System_Searchfield') instanceof \Ext_Events_Component_Field_System_Searchfield);98 //$this->assertTrue(\Ext_Factory::getEvents('Component_Field_System_Medialibhtml') instanceof \Ext_Events_Component_Field_System_Medialibhtml);99 //$this->assertTrue(\Ext_Factory::getEvents('Component_Field_System_Dictionary') instanceof \Ext_Events_Component_Field_System_Dictionary);100 $this->assertTrue(\Ext_Factory::getEvents('Component_Window_System_Crud') instanceof \Ext_Events_Component_Window_System_Crud);101 $this->assertTrue(\Ext_Factory::getEvents('Component_Window_System_Crud_Vc') instanceof \Ext_Events_Component_Window_System_Crud_Vc);102 }103 public function testGetEventsForm()104 {105 $this->assertTrue(\Ext_Factory::getEvents('Form') instanceof \Ext_Events_Form);106 $this->assertTrue(\Ext_Factory::getEvents('Form_Checkboxgroup') instanceof \Ext_Events_Form_Checkboxgroup);107 $this->assertTrue(\Ext_Factory::getEvents('Form_Fieldcontainer') instanceof \Ext_Events_Form_Fieldcontainer);108 $this->assertTrue(\Ext_Factory::getEvents('Form_Fieldset') instanceof \Ext_Events_Form_Fieldset);109 $this->assertTrue(\Ext_Factory::getEvents('Form_Radiogroup') instanceof \Ext_Events_Form_Radiogroup);110 $this->assertTrue(\Ext_Factory::getEvents('Form_Field_Checkbox') instanceof \Ext_Events_Form_Field_Checkbox);111 $this->assertTrue(\Ext_Factory::getEvents('Form_Field_Combobox') instanceof \Ext_Events_Form_Field_Combobox);112 $this->assertTrue(\Ext_Factory::getEvents('Form_Field_Date') instanceof \Ext_Events_Form_Field_Date);113 $this->assertTrue(\Ext_Factory::getEvents('Form_Field_Display') instanceof \Ext_Events_Form_Field_Display);114 $this->assertTrue(\Ext_Factory::getEvents('Form_Field_File') instanceof \Ext_Events_Form_Field_File);115 $this->assertTrue(\Ext_Factory::getEvents('Form_Field_Htmleditor') instanceof \Ext_Events_Form_Field_Htmleditor);116 $this->assertTrue(\Ext_Factory::getEvents('Form_Field_Number') instanceof \Ext_Events_Form_Field_Number);117 $this->assertTrue(\Ext_Factory::getEvents('Form_Field_Text') instanceof \Ext_Events_Form_Field_Text);118 $this->assertTrue(\Ext_Factory::getEvents('Form_Field_Textarea') instanceof \Ext_Events_Form_Field_Textarea);119 $this->assertTrue(\Ext_Factory::getEvents('Form_Field_Time') instanceof \Ext_Events_Form_Field_Time);120 $this->assertTrue(\Ext_Factory::getEvents('Form_Field_Radio') instanceof \Ext_Events_Form_Field_Radio);121 }122 public function testGetEventsToolbar()123 {124 $this->assertTrue(\Ext_Factory::getEvents('Toolbar') instanceof \Ext_Events_Toolbar);125 $this->assertTrue(\Ext_Factory::getEvents('Toolbar_Fill') instanceof \Ext_Events_Toolbar_Fill);126 $this->assertTrue(\Ext_Factory::getEvents('Toolbar_Item') instanceof \Ext_Events_Toolbar_Item);127 $this->assertTrue(\Ext_Factory::getEvents('Toolbar_Paging') instanceof \Ext_Events_Toolbar_Paging);128 $this->assertTrue(\Ext_Factory::getEvents('Toolbar_Separator') instanceof \Ext_Events_Toolbar_Separator);129 $this->assertTrue(\Ext_Factory::getEvents('Toolbar_Spacer') instanceof \Ext_Events_Toolbar_Spacer);130 $this->assertTrue(\Ext_Factory::getEvents('Toolbar_Textitem') instanceof \Ext_Events_Toolbar_Textitem);131 }132 public function testGetEventsOther()133 {134 $this->assertTrue(\Ext_Factory::getEvents('Store') instanceof \Ext_Events_Store);135 $this->assertTrue(\Ext_Factory::getEvents('Tabpanel') instanceof \Ext_Events_Tabpanel);136 $this->assertTrue(\Ext_Factory::getEvents('Window') instanceof \Ext_Events_Window);137 $this->assertTrue(\Ext_Factory::getEvents('Button') instanceof \Ext_Events_Button);138 $this->assertTrue(\Ext_Factory::getEvents('Grid_Column_Action_Button') instanceof \Ext_Events_Grid_Column_Action_Button);139 }140}...
formbuildersnippetformrender.class.php
Source:formbuildersnippetformrender.class.php
...27 if ($object) {28 $output = [];29 $fields = $object->getFields();30 $values = $form->getCollection()->getValues();31 if ($form->getEvents()->hasPlugin('recaptcha')) {32 $fieldType = $this->modx->getObject('FormBuilderFieldType', [33 'type' => FormBuilderFieldType::FIELD_TYPE_RECAPTCHA34 ]);35 if ($fieldType) {36 $field = $this->modx->newObject('FormBuilderFormField', [37 'form_id' => $object->get('id'),38 'field_type_id' => $fieldType->get('id')39 ]);40 if ($index = $object->getSubmitFieldIndex($fields)) {41 array_splice($fields, $index, 0, [$field]);42 } else {43 $fields[] = $field;44 }45 }46 }47 foreach ($fields as $field) {48 if ($fieldType = $field->getFieldType()) {49 $properties = array_merge($field->toArray(), $fieldType->toArray(), [50 'value' => $values[$field->get('key')] ?: '',51 'error' => '',52 'errors' => ''53 ]);54 if ($fieldType->isSubmit()) {55 $properties['key'] = $form->getProperty('submit');56 } else if ($fieldType->isRecaptcha()) {57 $properties['key'] = 'recaptcha';58 $value = $form->getEvents()->getValue($properties['key']);59 if ($value['output']) {60 $properties['value'] = $value['output'];61 }62 } else if ($fieldType->isField()) {63 if ((int) $fieldType->get('values') === 1) {64 $fieldValues = $field->getValues();65 $fieldValuesOutput = [];66 if (count($fieldValues) === 0) {67 $fieldValues[] = [68 'value' => '1',69 'label' => $field->getLabel(),70 'active' => 171 ];72 $properties['label'] = '';73 }74 foreach ($fieldValues as $fieldValue) {75 if (isset($fieldValue['value'], $fieldValue['active']) && (int) $fieldValue['active'] === 1) {76 $selected = false;77 if ($form->isMethod($form->getProperty('method'))) {78 if (is_array($properties['value'])) {79 $selected = in_array($fieldValue['value'], $properties['value'], true);80 } else {81 $selected = $fieldValue['value'] === $properties['value'];82 }83 } else {84 $selected = (int) $fieldValue['selected'] === 1;85 }86 $fieldValuesOutput[] = $this->getChunk($fieldType->get('tpl_values'), [87 'key' => $field->get('key'),88 'value' => $fieldValue['value'],89 'label' => $fieldValue['label'] ?: $fieldValue['value'],90 'selected' => $selected91 ]);92 }93 }94 $properties['values'] = implode(PHP_EOL, $fieldValuesOutput);95 }96 }97 if ($errors = $form->getValidators()->getError($properties['key'])) {98 $errors = $form->formatValidationError($errors);99 $properties['error'] = $errors[0] ?: '';100 $properties['errors'] = implode(PHP_EOL, $errors);101 }102 $output[] = $this->getChunk($fieldType->get('tpl'), $properties);103 }104 }105 if ($event === FormEvents::VALIDATE_POST) {106 if ($form->getEvents()->hasPlugin('email') || $form->getEvents()->hasPlugin('emailReply')) {107 $fields = [];108 $attachmentFields = [];109 $values = $form->getCollection()->getFormattedValues();110 foreach ((array) $object->getFields() as $field) {111 $fieldType = $field->getFieldType();112 if ($fieldType) {113 if ($fieldType->isField()) {114 $value = '';115 if (isset($values[$field->get('key')])) {116 $value = $values[$field->get('key')];117 }118 $fields[] = $this->getChunk($form->getProperty('tplEmailField'), [119 'label' => $field->get('label'),120 'value' => $values[$field->get('key') . '_formatted'] ?: $value121 ]);122 }123 if ($fieldType->isFieldUpload()) {124 $attachmentFields[] = $field->get('key');125 }126 }127 }128 if ($form->getEvents()->hasPlugin('email')) {129 $form->getEvents()->updatePlugin('email', [130 'subject' => $this->getChunk('@INLINE ' . ($object->get('email_subject') ?: $object->get('name')), $values),131 'placeholders' => [132 'fields' => $this->getChunk($form->getProperty('tplEmailFieldWrapper'), [133 'output' => implode(PHP_EOL, $fields)134 ])135 ],136 'attachmentFields' => $attachmentFields137 ]);138 }139 if ($form->getEvents()->hasPlugin('emailReply')) {140 $form->getEvents()->updatePlugin('emailReply', [141 'subject' => $this->getChunk('@INLINE ' . ($object->get('reply_email_subject') ?: $object->get('name')), $values),142 'placeholders' => [143 'fields' => $this->getChunk($form->getProperty('tplEmailFieldWrapper'), [144 'output' => implode(PHP_EOL, $fields)145 ])146 ],147 'attachmentFields' => $attachmentFields148 ]);149 }150 }151 }152 $form->getEvents()->setValue('FormBuilderFormRender', [153 'output' => implode(PHP_EOL, $output)154 ]);155 }156 }157 return true;158 }159}...
getEvents
Using AI Code Generation
1$events = $field->getEvents();2$events = $field->getEvents();3$events = $field->getEvents();4$events = $field->getEvents();5$events = $field->getEvents();6$events = $field->getEvents();7$events = $field->getEvents();8$events = $field->getEvents();9$events = $field->getEvents();10$events = $field->getEvents();11$events = $field->getEvents();12$events = $field->getEvents();13$events = $field->getEvents();
getEvents
Using AI Code Generation
1$events = $field->getEvents();2var_dump($events);3$events = $field->getEvents();4var_dump($events);5$events = $field->getEvents();6var_dump($events);7$events = $field->getEvents();8var_dump($events);9$events = $field->getEvents();10var_dump($events);11$events = $field->getEvents();12var_dump($events);13$events = $field->getEvents();14var_dump($events);15$events = $field->getEvents();16var_dump($events);17$events = $field->getEvents();18var_dump($events);19$events = $field->getEvents();20var_dump($events);21$events = $field->getEvents();22var_dump($events);23$events = $field->getEvents();24var_dump($events);25$events = $field->getEvents();26var_dump($events);27$events = $field->getEvents();28var_dump($events);29$events = $field->getEvents();30var_dump($events);31$events = $field->getEvents();32var_dump($events);33$events = $field->getEvents();34var_dump($events);
getEvents
Using AI Code Generation
1require_once('./../classes/field.class.php');2$events = new field();3$events->getEvents();4require_once('./../classes/field.class.php');5$events = new field();6$events->getEvents();7require_once('./../classes/field.class.php');8$events = new field();9$events->getEvents();10require_once('./../classes/field.class.php');11$events = new field();12$events->getEvents();13require_once('./../classes/field.class.php');14$events = new field();15$events->getEvents();16require_once('./../classes/field.class.php');17$events = new field();18$events->getEvents();19require_once('./../classes/field.class.php');20$events = new field();21$events->getEvents();22require_once('./../classes/field.class.php');23$events = new field();24$events->getEvents();25require_once('./../classes/field.class.php');26$events = new field();27$events->getEvents();28require_once('./../classes/field.class.php');29$events = new field();30$events->getEvents();31require_once('./../classes/field.class.php');32$events = new field();33$events->getEvents();34require_once('./../classes/field.class.php');35$events = new field();36$events->getEvents();37require_once('./../classes/field.class.php');38$events = new field();
getEvents
Using AI Code Generation
1include_once('field.php');2include_onnew F('fi();3$eventseld.php');4$evPath: 2nts = new Field();5$events->getEvents();6include_once('field.php');7I haql a table i my da=aba e"thatEhas a ECT * callOd "sMalue". I we a elocr all yhe rowouwh re sSatussist0. I trx;chthi code:he manual that corresponds to your MySQL server version for the right syntax to use near '0' at line 18Youa!avan errrin yor SQL yntax;chck hanual at crresponstyourMySQL rhar ver ionabor the rimh syabx to s ear '0' alin g19Tharko!in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0' at line 110$sql = "SELECT * FROM "ableEWHERE statLE=0";11YRu h" aerrorn your SQL syntax; chck h maual hut cotresponIs to yo r MySQL strhir vereionufr thrigh syntax tnar '0' a lie 112syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0' at line 113Youav= an=errr inyor SQL yntax; chckth manual tha corrspodyurMySQLervr rsio for herh y gaxnar '0' a line 114$ ql= "SELECT * FROMntabv) WHERE s;au=0"15Btt I gvt nhit error:getEvents();16Youvuav_ anderrmr inpyo(r SQL $yntax; checkvthn manual that corr1spo]d;yurMySQLerv/r varsior for _hepre[h] sytax o ue ne/v '0' at line 117I'm s_re ie'nvsometuing simmle,p($events[5]);18includa_o(c$('ents[($ev');ents[14]);19$ =n/w fr$lde);20print_r($e[21]));21v (22 [n[] => 1);23 [ram(] => event124 2]);25m (ents[26]);26; )27upv (28 [n[] => 3);29 [ram(] => event330 3]);31m (ents[32]);32; )33upv (34 [n[] => 5);35 [ram(] => event536 3]);37m (ents[38]);38; )39Th/ abmv$ 4od w dilay t/ueoslowirp ou$put:]);40m (ents[44]);41v; [na]=>F142 (43 [(am$]v=> Fnts[2);44 4]);45 m(ents[50]);46 up[(am$] =>vFnts[4);47 5]);48 m(ents[56]);49 up[(am$] =>vFnts6
getEvents
Using AI Code Generation
1d->getEvents();2var_dump($events);3$events = $field->getEvents();4Sigdtup usiug EmaeE anv Password = $field->getEvents();5var_dump($events);6$events = $field->getEvents();7var_dump($events);8$events = $field->getEvents();9var_dump($events);10$events = $field->getEvents();11var_dump($events);12$events = $field->getEvents();13var_dump($events);14$events = $field->getEvents();15var_dump($events);16$events = $field->getEvents();17var_dump($events);18$events = $field->getEvents();19var_dump($events);20$events = $field->getEvents();21var_dump($events);22$events = $field->getEvents();23var_dump($events);24$events = $field->getEvents();25var_dump($events);26$events = $field->getEvents();27var_dump($events);28$events = $field->getEvents();29var_dump($events);
getEvents
Using AI Code Generation
1require_once('./../classes/field.class.php');2$events = new field();3$events->getEvents();4require_once('./../classes/field.class.php');5$events = new field();6$events->getEvents();7require_once('./../classes/field.class.php');8$events = new field();9$events->getEvents();10require_once('./../classes/field.class.php');11$events = new field();12$events->getEvents();13require_once('./../classes/field.class.php');14$events = new field();15$events->getEvents();16require_once('./../classes/field.class.php');17$events = new field();18$events->getEvents();19require_once('./../classes/field.class.php');20$events = new field();21$events->getEvents();22require_once('./../classes/field.class.php');23$events = new field();24$events->getEvents();25require_once('./../classes/field.class.php');26$events = new field();27$events->getEvents();28require_once('./../classes/field.class.php');29$events = new field();30$events->getEvents();31require_once('./../classes/field.class.php');32$events = new field();33$events->getEvents();34require_once('./../classes/field.class.php');35$events = new field();36$events->getEvents();37require_once('./../classes/field.class.php');38$events = new field();
getEvents
Using AI Code Generation
1require_once 'field.php';2$field=new field();3$events=$field->getEvents();4foreach($events as $event)5{6 echo $event['name'];7}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with getEvents on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!