I am trying to add an ability to change the contents of one of the columns in the data table (its data cells should be editable). I was using this tutorial as a reference:
https://www.youtube.com/watch?v=LbhVVN5ffi0
its source code:
https://github.com/divanov11/table-edit-backend
And so, I have the following functions in my template:
function edit_description(place){
var targetId = $(this).attr("id");
var value = $(this).text();
var targetIN = $(this).attr("identificationNumber");
$(this).unbind();
$(this).html(`<input class="description form-control" data-target="${targetId}" type="text" value=${value}>`);
$(`.description`).on('keypress', function(e){
if (e.which == 13) {
var target = $(this).attr("data-target");
var description = $(`#${target}`).text($(this).val());
save_description(description, targetIN);
return false;
}
})
}
function save_description(description, identification_number){
console.log('Saved!');
var user_input = {"identificationNumber":identification_number, "description":description};
update_description_POST(user_input);
}
After typing in for example "chipset" I get the following description's value:
<td identificationnumber = "1234" id="description-1234">chipset</td>
I would need the description's value to be just "chipset". How to achieve that?
I have a a table that has four columns ID,NAME,SURNAME and RECIPIENT
Each button has a different value that is equal to the number of the ID that is in the same line as the button. For example the value of the first button is 2, second button 3 last button 123 all the buttons have id=contact. Each time i press a button i store the value of that button in a variable with the name input. My source code for that is:
var input; //prepare var to save contact name/ PLACE outside document ready
$(function() {
// contact form animations
$('button[id="contact"]').click(function() {
input = $(this).val(); //set var contactName to value of the pressed button
$('#contactForm').fadeToggle();
})
$(document).mouseup(function (e) {
var container = $("#contactForm");
if (!container.is(e.target) // if the target of the click isn't the container...
&& container.has(e.target).length === 0) // ... nor a descendant of the container
{
container.fadeOut();
}
});
});
Then i want to user this variable to fetch some files that are corresponded with the current varibale from firebase database. In my firebase database i have a folder with the name files that has three supfolders that coresponds to the values of the three buttons that i have
In general lines I click one of the three buttons (let's say the button in the first column), I store the value of the button(so now the input value will be equal to 2). Then i drug all the information that is stored in firebase database from files/2/. I have implemented the source code for that but I am not getting any results and when i run inspect console i am not getting any errors. The source code is the following :
var databaseRef = firebase.database().ref().child(`files/${input}/`);
var tblUsers = document.getElementById('tbl_users_list');
var rowIndex = 1;
databaseRef.once('value',function(snapshot){
snapshot.forEach(function(childsnapshot) {
var childKey = childsnapshot.key;
var childData = childsnapshot.val();
//var urls = childData.url;
var row = tblUsers.insertRow(rowIndex);
var cellId = row.insertCell(0);
var cellName = row.insertCell(1);
var button = row.insertCell(2);
var itd = document.createElement('input');
itd.setAttribute("type","button");
itd.setAttribute("value","View");
itd.onclick=function () {
window.open(childData.url);
};
cellId.appendChild(document.createTextNode(childData.filename));
cellName.appendChild(document.createTextNode(childData.created));
button.appendChild(itd);
rowIndex = rowIndex+1;
//document.write(username);
})
});
If in the above source code change the line var databaseRef = firebase.database().ref().child(`files/${input}/`); replacing the variable i stored the value of the button in the first function with 2 , 3 or 123 i am getting results so it seems the the problem is there but i dont know what else to do.
Can someone please help me ?
Thanks in Regards
This appears to be a perfect use case for the .dataset or data- attribute. MDN has a great page showing how to use this. Basically, store the uid as <data-uid = "ach782bckhbc23whatever"> in your HTML on the <tr> or the <button> element an on click, use evt.target.dataset.uid or evt.target.parentElement.dataset.uid to get the row's uid to make your .get() firebase call.
<div id="user" data-id="1234567890" data-user="johndoe" data-date-of-birth>John Doe</div>
let el = document.querySelector('#user');
// el.id == 'user'
// el.dataset.id === '1234567890'
// el.dataset.user === 'johndoe'
// el.dataset.dateOfBirth === ''
el.dataset.dateOfBirth = '1960-10-03'; // set the DOB.
// 'someDataAttr' in el.dataset === false
el.dataset.someDataAttr = 'mydata';
// 'someDataAttr' in el.dataset === true
This is the list of data in my firebase:
This is my source code:
var keys = firebase.database().ref().child('seller').once('child_added').then(function(datakey){
var makeList = firebase.database().ref('seller/' + datakey.getKey() +'/sellerName').once('value').then(function(snapshot){
var nama = snapshot.val();
var button = $(''+ nama + '');
button.appendTo('#sellerList');
});
});
My problem is, when I execute it, it only create a button element for Seller Name 'Miraak' only but not 'Khajiit'. Like this:
I want it to create a list of buttons based on the number of seller in my firebase. Like currently I have two seller, Miraak and Khajiit, I want both of them to appear as button list.
var keys = firebase.database().ref().child('seller/').once('value').then(function(datakey){
datakey.forEach(function(data){
var nama = data.val();
var button = $(''+ nama.sellerName + '');
button.appendTo('#sellerList');
});
});
Nevermind, I found the solution to my problem. Thank you.
I am trying to add a Mark all/Unmark all button in sub-list which is a type of inline-editor sub-list. below I have added a code for list type sub-list which will not work on inline-editor sub-list. Can anyone help to find this?
function button1Func(type) {
if (type=='edit' || 'view')
{
var record = nlapiLoadRecord(nlapiGetRecordType(), nlapiGetRecordId());
var intCount = record.getLineItemCount('item');
var headrow = document.getElementById("item_headerrow");
var head = headrow.insertCell(0);
head.innerHTML ="Select";
for (var rep = 1; rep <= intCount; rep++)
{
var row = document.getElementById("item_row_"+rep);
var x = row.insertCell(0);
var newCheckbox = document.createElement("INPUT");
newCheckbox.setAttribute("type", "checkbox");
newCheckbox.setAttribute("id", "select_CheckBox"+rep);
x.appendChild(newCheckbox);
}
}
}
function button2Func(type) {
if (type=='edit' || 'view')
{
var record = nlapiLoadRecord(nlapiGetRecordType(), nlapiGetRecordId());
var intCount = record.getLineItemCount('item');
for (var rep = 1; rep <= intCount; rep++)
{
var repId = record.getLineItemValue('item', 'item', rep);
if(document.getElementById("select_CheckBox"+rep).checked==true){
makecopyfun(repId);
}
else
{
continue;
}
}
alert("Success");
}
}
function makecopyfun(repId){
var record = nlapiLoadRecord(nlapiGetRecordType(), nlapiGetRecordId());
var intCount = record.getLineItemCount('item');
record.insertLineItem('item',intCount + 1);
alert (intCount);
record.setCurrentLineItemValue('item','item',repId);
record.commitLineItem('item');
var id = nlapiSubmitRecord(record, true);
}
Not sure through the API because there's no record object, you could try using jQuery.
First write following code & create userEvent script and apply function name(initnoload) in beforeLoad Event.
Then Deploy that script on Quote.
function initonload(type, form, request) {
if (type=='edit' || type=='view') {
var list = form.getSubList("item");
list.addButton('custpage_markmark','Mark all','markall();'); //markall(); is function name from the client script
list.addButton('custpage_unmarkmark','Unmark all','unmarkall();'); //unmarkall(); is function name from client script
form.setScript('customscript_mark_all_item_quote'); // 'customscript_mark_all_item_quote' is the ID of script
}
}
Above code will add two buttons to Sublist and their action get executed in client script whose ScriptId we have Defined.
Now write the following code & create client script.(Note: Just save the client script, Don't specify any event function name and do not deploy it).
function markall() {
var count=nlapiGetLineItemCount('item'); //gets the count of lines
for(var i=1;i<=count;i++) {
nlapiSelectLineItem('item',i);
nlapiSetCurrentLineItemValue('item','custcol_checkbox_field','T',true,true); //'custcol_checkbox_field' is checkbox's field ID.
}
nlapiCommitLineItem('item');
}
function unmarkall() {
var count=nlapiGetLineItemCount('item');
for(var i=1;i<=count;i++) {
nlapiSelectLineItem('item',i);
nlapiSetCurrentLineItemValue('item','custcol_checkbox_field','F',true,true); //'custcol_checkbox_field' is checkbox's field ID.
}
nlapiCommitLineItem('item');
}
After saving the client script please paste it's ID in user event's form.setScript('Client script ID'). function
i hope this will help you out.
Please let me know if u face any difficulty.
Thank you.
I do came up with other idea as you can use the field which'll help you to mark/unmark all lines under sublist..you can add subtab to the form and under subtab you can add field and sublist. later you can apply script on that field which will help you to mark/unmark all sublist lines.
Here is the code...
form.addSubTab('custpage_tab', 'Main Tab');
form.addField('custpage_chkmark','checkbox','Mark/Unmark All',null,'custpage_tab');
form.addSubList('custpage_sublst','inlineeditor','SampleSubList','custpage_tab');
I am looking for guidance to look for a way to accomplish some difficulty in programming that I don't have the experience to create.
I am using Spiceworks with a custom plugin called Plugin Bulk Delete and Close and it works fine but I need an additional logic. I have a custom attribute called Master Number where I can specify relations on tickets screenshot.
I'm looking for a way that in case a ticket is selected to close all with the same Master Number. Well, my programming is very limited and I just started with prototype and reading about jquery for a month and a half now. Any help or direction is all I need this is possibly very simple but not for me.
SPICEWORKS.app.helpdesk.ready(function(){
if(document.URL.indexOf("Master_View") >= 0){
if ($('Multi-Toolbar') === null)
{
var toolbarDInsert = '<a class="delete toolbar_buton" href="#" id="plugin-Dactions">';
var toolbarCInsert = '<a class="clopen toolbar_buton" href="#" id="plugin-Cactions"><span class="inner icon">Close/Open Ticket(s)</span></a>';
var cbInsert = '<span style="float:left;"><input type="checkbox" class="plugin-operation" name="cbselection" /></span>';
var HdInsert = 'div#ticket-list-body table tr td.cell-status';
var thinsert = '<div id="Multi-Toolbar" class="sui-toolbar"><tr><th><input type="checkbox" id="plugin-all" /></th></tr></div>';
plugin.includeStyles();
$('primary').insert({top:thinsert});
$('Multi-Toolbar').insert(toolbarCInsert);
$('Multi-Toolbar').insert(toolbarDInsert);
var insertcheckbox = function(actions){
actions.style.width = '2.5em';
actions.insert({top:cbInsert});
};
$$(HdInsert).each(insertcheckbox);
$('plugin-Cactions').observe('click', function(event){
event.stop();
var entries = $$('input.plugin-operation').select(function(input){
return input.checked;
}).collect(function(input){
return input.up('tr').id.replace('ticket-', '');
});
if(entries.size() > 0){
var answer = confirm('You are about to Close / Open ' + entries.size() + ' Ticket(s) Relying on the Ticket(s) state. \nContinue ?') ;
if (answer){
entries.each(function(entry){ new Ajax.Request('/tickets/toggle_status/' + entry);
});
}}
if(entries.size() <= 0){
alert('No ticket(s) selected, please select at least one ticket');
}
});
$('plugin-all').observe('click',function (e) {
var toggle = $('plugin-all').checked;
$$('div#ticket-list-body input[type=checkbox]').each(function(check) {
check.checked = toggle;
});
});
}
}
});