I have some code which worked in JayData 1.3.
I need to upgrade JayData to 1.5 due to the compatibility issues the 1.3 version has with polymer.
The upgrade instructions say you can use the "jaydata-compatibility.js" script to "upgrade your app to JayData 1.5.x from previous versions step-by-step", however when I add that in as described I simply get the error, "typeOrName requires a value other than undefined or null", which actually doesn't help me step through the upgrade at all.
Here is the JayData 1.3 code :
$data.Entity.extend('Cache', {
'id': { 'type': 'int', 'key': true, 'computed': true },
'url': { 'type': 'string' },
'method': { 'type': 'string', 'required': true },
'dts': { 'type': 'string', 'required': true },
'encryptMeth': { 'type': 'string' },
'data': { 'type': 'string' }
});
$data.EntityContext.extend('APIWrapperDB', {
'Cache': { 'type': $data.EntitySet, 'elementType': Cache }
});
var cacheDatabase = new APIWrapperDB('TheAPIWrapperDatabase');
cacheDatabase.onReady( function() { /* now my DB is ready */ };
What is the JayData 1.5 equalivalent of this code?
This is the updated snippet, I've just declared your entity definitions as variables as JayData stopped using global objects.
var Cache = data.Entity.extend('Cache', {
'id': { 'type': 'int', 'key': true, 'computed': true },
'url': { 'type': 'string' },
'method': { 'type': 'string', 'required': true },
'dts': { 'type': 'string', 'required': true },
'encryptMeth': { 'type': 'string' },
'data': { 'type': 'string' }
});
var APIWrapperDB = $data.EntityContext.extend('APIWrapperDB', {
'Cache': { 'type': $data.EntitySet, 'elementType': Cache }
});
var cacheDatabase = new APIWrapperDB('TheAPIWrapperDatabase');
cacheDatabase.onReady( function() { /* now my DB is ready */ };
Related
When I have an object and I put it as an extension of another object in which I put value for some of the extended fields - is it going to be rewritten or the value will be added to the old one?
For example if I have:
const PATCH_REQUEST_SCHEMA = {
'type': 'object',
'title': 'Some object',
'description': 'Some object Representation',
'properties': {
'name': {
'type': 'string',
'minLength': 1,
'maxLength': 256,
'title': 'Name'
}
};
const POST_REQUEST_SCHEMA = _.extend({}, PATCH_REQUEST_SCHEMA, {
'properties': {
'surname': {
'type': 'string',
'minLength': 1,
'maxLength': 256,
'title': 'Surname'
}
}
});
What would be the result for POST_REQUEST_SCHEMA.properties ?
Will it be:
{
'name': {
'type': 'string',
'minLength': 1,
'maxLength': 256,
'title': 'Name'
},
'surname': {
'type': 'string',
'minLength': 1,
'maxLength': 256,
'title': 'Surname'
}
}
or:
{
'surname': {
'type': 'string',
'minLength': 1,
'maxLength': 256,
'title': 'Surname'
}
}
I tested it manually - it rewrites/overrides the field "properties". So the answer is:
{
'surname': {
'type': 'string',
'minLength': 1,
'maxLength': 256,
'title': 'Surname'
}
}
I'm building a configurator in AngularJS that uses the object $scope.data to allow users to edit the object via the front-end. The user can then save this object to a separate array in $scope.builds, allowing them to have multiple configurations. Here is the function that adds another configuration to $scope.builds.
$scope.addition = function(){
var newData = angular.copy($scope.data);
$scope.builds.push(newData);
}
Unfortunately, despite using the angular.copy function, all of the objects in the array of $scope.builds seem to be the same $scope.data object duplicated over and over.
EDIT:
Here is an abridged version of what $scope.data looks like:
$scope.data = [
{
'title': 'Select your configuration',
'required': true,
'options': [
{
'name': 'Option 1',
'select': true,
'filter': true
}, {
'name': 'Option 2',
'select': false,
'filter': true
}, {
'name': 'Option 3',
'select': false,
'filter': true
}
]
}, {
'title': 'Select your configuration',
'required': true,
'options': [
{
'name': 'Option 1',
'select': true,
'filter': true
}, {
'name': 'Option 2',
'select': false,
'filter': true
}, {
'name': 'Option 3',
'select': false,
'filter': true
}
]
}
];
I have implemented handsontable for getting data from user.
This is my script
<script type="text/javascript">
$(document).ready(function() {
$('#quiz_questions').handsontable({
rowHeaders: true,
colHeaders: ['Question', 'Option 1', 'Option 2', 'Option 3', 'Option 4', 'Answer', 'Marks'],
columns: [
{
type: 'text',
allowEmpty: false
},
{
type: 'text',
allowEmpty: false
},
{
type: 'text',
allowEmpty: false
},
{
type: 'text',
allowEmpty: true
},
{
type: 'text',
allowEmpty: true
},
{
type: 'dropdown',
source: ['Option 1', 'Option 2', 'Option 3', 'Option 4'],
allowEmpty: false
},
{
type: 'numeric',
allowEmpty: false
}
],
stretchH: 'all',
minSpareRows: 0,
minSpareColumns: 0,
minRows : 25
});
var hotInstance = $("#quiz_questions").handsontable('getInstance');
$('#btnSave').click(function(e){
e.preventDefault();
$('#btnSave').prop("disabled", true);
//alert('btnclicked');
var dynFrm = $('<form>', {
'action': '{{ action('QuizQuestionController#storeBulk') }}',
'method': 'POST'
}).append($('<input>', {
'type': 'hidden',
'name': '_token',
'value': '{{ csrf_token() }}'
})).append($('<input>', {
'type': 'hidden',
'name': 'quiz_id',
'value': '{{ $quiz->quiz_id }}'
})).append($('<input>', {
'type': 'hidden',
'name': 'data',
'value': JSON.stringify(hotInstance.getData())
}));
dynFrm.appendTo(document.body).submit();
});
});
</script>
The storeBulk() function of QuizQuestionController processes the data.
public function storeBulk()
{
// get the quiz model
$quiz = Quiz::findOrFail(Input::get('quiz_id'));
// get the data
$data = Input::get('data');
$jData = json_decode($data);
//process the recevied data
foreach($jData as $row) {
$quizQuestion = new QuizQuestion();
$quizQuestion->quiz_id = $quiz->quiz_id;
$quizQuestion->question_no = $cnt;
$quizQuestion->question_text = trim($row[0]) ? : null;
$quizQuestion->options = $this->processOptions([
trim($row[1]),
trim($row[2]),
trim($row[3]),
trim($row[4])
]);
$quizQuestion->answer = $this->processAnswer($row[5]);
$quizQuestion->marks = trim($row[6]) ? : null;
...
}
Now the problem is, for rows that are left empty in the handsontable while filling the data, I should get data for those rows as [null,null,null,null,null,null,null]. But this is not the case. For some rows I get [null,null,null,null,null] (only 5 values). Thus I get an ErrorException saying Undefined offset: 5.
I have noticed this happens for first 5 rows only. What could be the problem?
Pinpointed the problem.
I have noticed this happens for first 5 rows only. What could be the
problem?
There's a startRows property of handsontable which defaults to 5. Hence the problem with the first 5 rows. I set the property explicitly to
startRows: 0,
And also modified the storeBulk() function to ignore errors.
$quizQuestion->question_text = trim(#$row[0]) ? : null;
$quizQuestion->options = $this->processOptions([
trim(#$row[2]),
trim(#$row[3]),
trim(#$row[4]),
trim(#$row[5])
]);
$quizQuestion->answer = $this->processAnswer(#$row[6]);
$quizQuestion->marks = trim(#$row[7]) ? : null;
Now everything works correctly.
Have you tried using hotInstance.getSourceData() instead of hotInstance.getData()? The functionality for this method changed with its latest release which has been causing similar issues for other people.
I have inherited an ExtJs4 project, and I've got a fairly basic question.
I have a view that has a newly added checkbox field as one of the items, like so:
{
boxLabel: 'Test Message?',
xtype: 'checkboxfield',
id: 'cbTextMessage',
checked: false,
name: 'testMessage',
inputValue: true,
uncheckedValue: false
}
When the record is active, this value changes to the appropriate checked or unchecked state. When creating a new record, the value is set to the value of the checkbox. However, when editing an existing record, the model never gets updated to any value other than the original value.
The model:
Ext.define('PushAdmin.model.Message', {
extend: 'Ext.data.Model',
idProperty: 'id',
requires: ['Proxy.ParameterProxy'],
fields: [
{ name: 'id', type: 'int' },
{ name: 'games', type: 'auto',
convert: function(data, model) {
data = ( data && !Ext.isArray(data) ) ? [data] : data;
return data;
}
},
{ name: 'msgEnglish', type: 'string' },
{ name: 'msgFrench', type: 'string' },
{ name: 'msgSpanish', type: 'string' },
{ name: 'testMessage', type: 'bool' },
{ name: 'sendAt', type: 'date' },
{ name: 'note', type: 'string'},
{ name: 'status', type: 'string' },
],
proxy: {
type: 'rest',
url: '/apnsadmin/rest/Message',
pageParam: undefined,
startParam: undefined,
limitParam: undefined,
reader: {
type: 'json',
root: 'data',
successProperty: 'success'
}
}
});
And finally this is the function that gets called when the save button is clicked.
click: function () {
var grid = this.getQueuedMessagesGrid();
var sm = grid.getSelectionModel();
var selectedRecord = sm.getCount() > 0 ? sm.getSelection()[0] : undefined;
this.getMessageForm().getForm().updateRecord();
var newRecord = this.getMessageForm().getForm().getRecord();
if (selectedRecord!=undefined) {
console.log(selectedRecord);
console.log(newRecord);
selectedRecord.save();
} else {
// New record!
console.log("Saving new record");
grid.getStore().add(newRecord);
newRecord.save();
}
this.getMessageForm().setDisabled(true);
this.getMessageForm().getForm().reset();
}
},
I am aware that things are probably not the proper ExtJS way to do things, but since this is mostly working I am trying not to have to rewrite large chunks of it. I'd just like to know what I'm doing wrong in adding this checkbox/boolean field to the form.
The model:
Ext.ns('Workout.Models.user');
Ext.regModel('User', {
fields: [{
name: 'member_id',
type: 'int'
}, {
name: 'first_name',
type: 'string'
}, {
name: 'last_name',
type: 'string'
}, {
name: 'username',
type: 'string'
}, {
name: 'password',
type: 'string'
}, {
name: 'dob',
type: 'date',
dateFormat: 'Y-m-d'
}, {
name: 'email_address',
type: 'string'
}, {
name: 'is_active',
type: 'int'
}],
proxy: {
type: 'ajax',
format: 'json',
url: '../../_dev/json_fixtures/users.json',
reader: {
type: 'json',
root: 'users'
},
root: 'users'
}
});
The Store:
Ext.ns('Workout.Stores');
Workout.Stores.user = new Ext.data.Store({
model: 'User',
storeId : 'Workout.Stores.user',
sorters: [
'last_name',
'first_name',
'member_id'
],
autoLoad: true
});
The Grid:
Ext.ns('Workout.User');
Workout.User.grid = new Ext.grid.Panel({
store: 'Workout.Stores.user',
columns:[{
text: 'Created At',
dataIndex: 'created_at'
}, {
text: 'First Name',
dataIndex: 'first_name'
}]
});
The JSON File
{
"users":[{
"created_at":"2011-04-01 14:13:34",
"member_id":"14453",
"first_name":"Jemima",
"last_name":"Petersen",
"username":"jpeterson",
"password":"TDW29HOH7WY",
"dob":"1960-07-03",
"email_address":"at.velit.Pellentesque#sociis.com"
}]
}
Wheh I load my HTML page, the grid is empty. However, if I supply raw data to the store via the data param, it loads. If I call User.load() manually via the console, nothing happens. If i call User.load() and pass in a valid JSON object,nothing happens.
Is there something I'm missing / not doing right?
You have done everything expect set the height of your grid panel. You need to set the height to display the records. Here is what I would add to your grid panel config:
height: 300
Now, apart from this, you have other problems like you have not defined created_at in your User model. If you plan to display the value in your grid, you need to update your model as well.
Ext.define(
'BK.store.Categories'
, { extend : 'Ext.data.Store'
, model : 'BK.model.Category'
, autoload : true
, proxy : { type : 'ajax'
, format : 'json'
, root : 'results'
, api : { read : 'data/data1.json' }
, reader : new Ext.data.JsonReader({ type : 'json'
, root : 'results'
, successProperty : 'success'
})
}
}
);
when I use data hardcoded in the store, it works OK (so model, view, controller are OK), as soon as I use the proxy it behaves as if autoload were FALSE, no net request