How to add items to nested array - angularjs - asp.net

This is the structure of nested array:
$scope.History = [
{
isCustomer:false,
userText:"some text",
options:[]
}
The array with data:
//The text in DisplayLabel will be the same for all the objects.
$scope.Categories = [
{ "QuestionId": 1, "QuestionName": "Complaint", "DisplayLabel": "what is it?" },
{ "QuestionId": 2, "QuestionName": "Registration", "DisplayLabel": "what is it?" }
];
Desired Array:
$scope.History = [
{
isCustomer:false,
userText:"what is it?",
options:["Complaint","Registration"]
}
Normally I would do this for a 1D array
angular.forEach($scope.Categories, function (value, key) {
$scope.History.push(false,value.DisplayLabel);
Now, how to add items to 'options' for an object.
EDIT:
I tried this but no luck. Doesn't display any data
var optionsData = [];
var userText = "";
angular.forEach($scope.Categories, function (value, key) {
optionsData.push(value.QuestionName);
userText = value.DisplayLabel;
})
$scope.History.push(false,userText,optionsData);

var app = angular.module('app', []);
app.controller('homeCtrl', function($scope) {
$scope.History = [{
isCustomer: false,
userText: "some text",
options: []
}]
$scope.Categories = [{
"QuestionId": 1,
"QuestionName": "Complaint",
"DisplayLabel": "what is it?"
}, {
"QuestionId": 2,
"QuestionName": "Registration",
"DisplayLabel": "what is it?"
}];
var optionsData = []
angular.forEach($scope.Categories, function(value, key) {
$scope.History[0].options.push(value.QuestionName)
});
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<div ng-app="app">
<div ng-controller="homeCtrl">
<pre>{{History | json}}</pre>
</div>
</div>

Related

How to securely pass values from SuiteScript suitelet to an HTML page?

I am attempting to pass values from a Suitelet to an HTML page that is being inserted into an INLINEHTML field in the Suitelet form. However, I am unsure of the best way to accomplish this. I am currently doing it in this manner, but I want to ensure that I am using a somewhat secure method ideally, as opposed to allowing for XSS vulnerabilities.
Suitelet INLINEHTML field:
var htmlForm = form.addField({
id: 'custpage_htmlform',
type: ui.FieldType.INLINEHTML,
label: 'HTMLFORM'
});
var fileObj = file.load({
id: 123
});
var htmlContent = fileObj.getContents();
htmlContent = htmlContent.replace("['REPLACETHIS']","['<input type=\"radio\" name=\"selectRow\" />','EXAMPLE','1234','1245','01/2021','<img src=\"https://imageurl.example" />'];");
htmlForm.defaultValue = htmlContent;
HTML example:
<table id="example" class="display" style="width:100%">
</table>
<br />
<script>
//Main Data Table
var exampleValues = new Array();
var exampleDetailArr = ['REPLACETHIS'];
exampleValues.push(exampleDetailArr);
window.$vars = {
exampleValues: exampleValues
}
$(document).ready(function() {
$('#example').DataTable( {
data: exampleValues,
"bJQueryUI": true,
columns: [
{ title: "Select" },
{ title: "Type" },
{ title: "Internal ID" },
{ title: "External ID "},
{ title: "Date" },
{ title: "Memo" },
],
"columnDefs": [
{
"targets": [ 3 ],
"visible": false,
"searchable": false
}
]
} );
} );
</script>

filter by category work not properly with remote search?

Hello I have problem compute vue filter by category it work not properly when I add item on Service tab and then click on Medicine tab remote search item by category it will stuck and filter not work and when I click in Service tab back it show only number 2.
this my template
<el-table
:data="itemFilters"
row-key="no"
style="width: 100%"
>
This my script
computed: {
itemFilters() {
const self = this
let item = self.form.items.filter(o => {
return o.categoryName === self.tabActive || o.itemId === ''
})
return item
},
},
this Method
methods: {
_getItemOpts(query, type) {
let exp = new RegExp(query)
let selector = {
$or: [
{ name: { $regex: exp, $options: 'i' } },
{ refNo: { $regex: exp, $options: 'i' } },
{ barcode: { $regex: exp, $options: 'i' } },
],
activityType: { $in: ['Sale'] },
status: 'Active',
'catDoc.name': this.tabActive,
}
// For form Sale Return and receipts refund
if (this.formName == 'Sale_Return' || this.formName == 'Receipt_Refund') {
selector.itemType = { $ne: 'Bundle' }
}
findItems
.callPromise({ selector: selector })
.then(result => {
// this.itemOpts = result
if (type == 'remote') {
// For remote
this.form.items[this.activeIndex].itemOpts = result
} else {
// For scan barcode
let item = result[0]
if (item) {
let row = {
itemId: item._id,
itemType: item.itemType,
memo: '',
qty: 1,
qtyRate: 1,
unitId: item.units[0].unitId,
units: item.units,
price: item.price,
amountBeforeDiscount: item.price,
discountRate: 0,
discountValue: 0,
amountAfterDiscount: item.price,
taxId: '',
taxAmount: 0,
// For expand bundle item
subItems: [],
expand: 'expand',
// For sales only(cash sales and invoice)
// refSaleOrderId: '',
// refSaleOrderDetailId: '',
// refNo: '',
itemOpts: result,
}
this.form.items.push(row)
} else {
Notify.warning({ message: 'This item do not set barcode!' })
}
}
this.loading = false
})
.catch(err => {
this.loading = false
this.$notify.error(err.reason)
})
},
}
Please help...

Grid dont have data Kendo UI and AngularJS in ASP.NET MVC

Im using KendoUI, AnduglarJS in ASP.NET MVC 4.
Im trying get data and show in grid, but my grid is not showing data.
Data is downloaded from db and I have they in js.
list.cshtml
<div class="panel panel-default" ng-controller="app.views.register.list as vm">
<div kendo-grid k-data-source="vm.registers" k-selectable="'row'"
k-pageable='{ "refresh": true, "pageSizes": true }'
k-on-change="vm.handleChange(kendoEvent)"
k-columns='[
{ "field": "type", "title": "Typ"},
{ "field": "status", "title": "Status"},
{ "field": "ip", "title": "IP"},
{ "field": "description", "title": "Opis"},
{ "field": "createdDate", "title": "Data utworzenia", type: "datetime", format: "{0:d}"}
]'>
</div>
</div>
list.js
(function () {
var app = angular.module('app');
var controllerId = 'app.views.register.list';
app.controller(controllerId, [
'$scope', '$location', 'abp.services.app.register',
function ($scope, $location, registerService) {
var vm = this;
var localize = abp.localization.getSource('Ebok');
//kendo.culture("en-EN");
vm.handleChange = function (kendoEvent) {
var grid = kendoEvent.sender;
var selectedData = grid.dataItem(grid.select());
var id = selectedData.id;
vm.changeRegister(id);
}
vm.registers = new kendo.data.ObservableArray([]);
registerService.getRegisters({ PageSize: 20 }).success(function (data) {
vm.registers = new kendo.data.ObservableArray(data.registers);
});
}
]);
})();
In vm.registers I have data, here is example:
{"type":"dfdgf","status":"dfdrf","ip":"dfdf","description":"cdsdfsdfs666","createdDate":"2014-12-29T12:09:55.16","id":1}
What is wrong?
Problem was in configuration.
In file app.js I dont have one line 'kendo.directives'
var app = angular.module('app', [
'ngAnimate',
'ngSanitize',
'ui.router',
'ui.bootstrap',
'ui.jq',
'abp',
'kendo.directives'
]);

datagrid's editor can not align and auto fill the cell

I use easyui implements inline edit of datagrid,dynamically add new rows and save back by one click. But when click a row and starting to edit, the editor in the cell can not align to it's column and can not auto fill the whole cell. So it looks a mess.
The essential code is below:
//add numberspinner into datagrid.
$.extend($.fn.datagrid.defaults.editors, {
numberspinner: {
init: function(container, options){
var input = $('<input type="text">').appendTo(container);
return input.numberspinner(options);
},
destroy: function(target){
$(target).numberspinner('destroy');
},
getValue: function(target){
return $(target).numberspinner('getValue');
},
setValue: function(target, value){
$(target).numberspinner('setValue',value);
},
resize: function(target, width){
$(target).numberspinner('resize',width);
}
},
empty:{
init: function(container, options){
return $('<div style="padding:0 4px"></div>').appendTo(container);
},
getValue: function(target){
return $(target).html();
},
setValue: function(target, value){
$(target).html(value);
}
}
});
var editIndex = undefined;
$(function(){
$('#dg').datagrid({onClickRow:function(index,data){
var row=$('#dg').datagrid('getSelected');
}});
$('#adddg').datagrid({
columns: [[{
field:'id',hidden:true
},{
field:'code',title:'代码',width:"50",hidden:true,
editor:{type:'text'}
},{
field:'name',title:'所属线路',width:"100",
editor:{
type:'combobox',
options:{
valueField:'text',
textField:'text',
url:"<c:url value='/nnmis/view/zzjg/comboidLine.tg'/>",
onSelect:function(item){
var ed = $('#adddg').datagrid('getEditor', {index:editIndex,field:'code'});
$(ed.target).val(item.id);
}
}
}
},{
field:'seq',title:'线路中排序',width:"60",
editor:{
type:'text',
min:0
}
},{
field:'kmupstart',title:'上行公里开始',width:"70",
editor:{
type:'numberspinner',
min:0
}
},{
field:'kmupend',title:'上行公里结束',width:"70",
editor:{
type:'numberspinner',
min:0
}
},{
field:'kmdownstart',title:'下行公里开始',width:"70",
editor:{
type:'numberspinner',
min:0
}
},{
field:'kmdownend',title:'下行公里结束',width:"70",
editor:{
type:'numberspinner',
min:0
}
}]],
onClickRow:function(index,data){
var row=$('#adddg').datagrid('getSelected');
if(editIndex == undefined){
$('#adddg').datagrid('beginEdit', index);
editIndex = index;
}else{
$('#adddg').datagrid('endEdit', editIndex);
$('#adddg').datagrid('beginEdit', index);
editIndex = index;
}
},
onBeforeEdit:function(index,row){
row.editing = true;
updateActions(index);
},
onAfterEdit:function(index,row){
row.hadedit='1';
row.editing = false;
updateActions(index);
},
onCancelEdit:function(index,row){
row.editing = false;
updateActions(index);
}
});
});
function updateActions(index){
$('#adddg').datagrid('updateRow',{
index: index,
row:{}
});
}
function getRowIndex(target){
var tr = $(target).closest('tr.datagrid-row');
return parseInt(tr.attr('datagrid-row-index'));
}
function addline(){
/*var dta = $('#adddg').datagrid('getData');
if(dta){
if(dta.rows.length == 0){
$('#adddg').datagrid('appendRow',{
id:'',
code:'',
seq:'0',
kmupstart:'0',
kmupend:'0',
kmdownstart:'0',
kmdownend:'0'
});
}
}*/
$('#adddg').datagrid('appendRow',{
id:'',
code:'',
seq:'0',
kmupstart:'0',
kmupend:'0',
kmdownstart:'0',
kmdownend:'0'
});
}
I had the same issue when I didn't wrapped the output with <html><body> tags.
When I added <html><body> everything became OK.

ExtJS4 fireEvent in select event checkcolumn not work

I am trying to use dummy event handler on select event on Ext.grid.Panel. But if I use fireEvent('RequestSelect'), to external observer(controller) checkcolumn is not working on selected row or after navigating with arrows on keyboard. If I comment row with this.fireEvent('RequestSelect') checkcolumn works good.
Ext.define('OrionWebClient.view.RequestList',{
extend: 'Ext.grid.Panel',
id:'rqstlst',
title:'Список запросов',
alias:'widget.requestlist',
border:true,
requires:['Client.model.Request'],
columns:{
defaults:{
draggable:false,
sortable:false,
hideable:false,
resizable:false
},
items:[
{ text: '#', xtype:'rownumberer', width: 30 },
{ text: 'команда', dataIndex: 'commandName', width: 250},
{ text: 'параметры', dataIndex: 'params', width: 250},
{ text: '*', dataIndex: 'check', xtype: 'checkcolumn', width: 30 }
]
},
store:{
model: 'Client.model.Request',
autoLoad:true
},
initComponent:function () {
this.callParent();
this.on({
select:this._OnRequestSelect
});
this.SetCurrentIndex(-1);
this.addEvents({
RequestSelect:true,
AddRequest: true,
RemoveRequest: true,
RequestUp: true,
RequestDown: true
});
},
GetCurrentIndex:function(){
return this.m_cur_index;
},
SetCurrentIndex:function (index,render) {
if (render){
var smodel = this.getSelectionModel();
if (index == -1){
smodel.deselectAll();
this.fireEvent('Deselect');
}
else{
smodel.select(index);
}
}
this.m_cur_index = index;
},
_OnSendRequest:function () {
var rqst_list = this._GetRequestToSend();
this.fireEvent('RequestSend',rqst_list);
},
_OnRequestSelect:function(grid, rec, index){
this.SetCurrentIndex(index, false);
this.fireEvent('RequestSelect', rec);
},
MoveSelection:function(start, stop, direct){
var index = {
_old: this.GetCurrentIndex(),
_new: this.GetCurrentIndex()
};
if (index._old==-1){
this.SetCurrentIndex(start,true);
return index;
}
if (index._old==stop){
return index;
}
index._new += direct;
this.SetCurrentIndex(index._new,true);
return index;
},
_OnButtonUp:function(){
var max = this.GetMaxIndex();
var index = this.MoveSelection(max, 0, -1);
this.fireEvent('RequestMove',index);
},
_OnButtonDown:function(){
var max = this.GetMaxIndex();
var index = this.MoveSelection(0, max, 1);
this.fireEvent('RequestMove', index);
},
GetMaxIndex:function () {
var store = this.getStore();
return store.getCount()-1;
}
});
PS Sorry my English is bad =(
There are several ways in handle events, the one i prefer is just listen for these events inside your controller without adding any logic to your view.
Ext.define('OrionWebClient.controller.Main', {
extend: 'Ext.app.Controller',
views: [
'RequestList'
],
init: function() {
this.control({
'RequestList': {
select: this.onSelect
}
});
},
onSelect: function(this, record, index, eOpts){
console.log('selected'+record);
}
});

Resources