How to get the full name of an object? - backbone.js

What should www, xxx, yyy and zzz be in the following?
window.App = new Backbone.Marionette.Application();
App.module('ContactMgr.Detail', function (Detail, App, ... ) {
Detail.Layout = Marionette.LayoutView.extend({
initialize: function () {
console.log( www ); // prints 'Layout'
console.log( xxx ); // prints 'Detail'
console.log( yyy ); // prints 'App.ContactMgr.Detail'
console.log( zzz ); // prints 'App.ContactMgr.Detail.Layout'
// (if not concatenating yyy and www)
};
});
)};

Related

Error displaying data - scope - AngularJS

I have a problem with displaying data using AngularJS.
So my application is based on AngularJS and CodeIgniter 3.
I've created a validation in CodeIgniter written in the form, everything works.
public function create()
{
$this->form_validation->set_error_delimiters('','');
$this->form_validation->set_rules( 'login' , 'Imię' , 'required|min_length[3]' );
$this->form_validation->set_rules( 'email' , 'Email' , 'required|valid_email|is_unique[users.email]' );
$this->form_validation->set_rules( 'password' , 'Hasło' , 'required|matches[passconf]' );
$this->form_validation->set_rules( 'passconf' , 'Powtórz hasło' , 'required|matches[password]' );
if ( $this->form_validation->run())
{
$user = $this->input->post('user');
unset($user['passconf']);
$user['password'] = crypt($user['password'], config_item('encryption_key'));
$this->Users_model->create($user);
}
else
{
$errors['login'] = form_error( 'login' );
$errors['email'] = form_error( 'email' );
$errors['password'] = form_error( 'password' );
$errors['passconf'] = form_error( 'passconf' );
echo '{"records":' . json_encode( $errors ) . '}';
}
}
On the AngularJS side, I wanted errory to appear.
controllersAdmin.controller('userCreate', function( $scope, $http, $timeout ){
$scope.user = {};
$scope.user.role = 'user';
$scope.createUser = function( user ){
$http({
method: 'POST', url: 'api/admin/users/create/' ,
data: {
user : user,
login : user.login,
email : user.email,
password : user.password,
passconf : user.passconf
}}
).then(function ( errors ){
if ( errors )
{
$scope.errors = errors;
}
else
{
$scope.success = true;
$timeout(function(){
$scope.success = false;
$scope.user = {};
} , 3000 );
}
},function (error){
console.log('Blad we wczytywaniu danych');
});
}
});
I created $scope.errors = errors;
When I display it with {{errors}} - data is displayed.
{"data":{"records":{"login":"Pole Imię jest wymagane.","email":"Pole Email jest wymagane.","password":"Pole Hasło jest wymagane.","passconf":"Pole Powtórz hasło jest wymagane."}},"status":200,"config":{"method":"POST","transformRequest":[null],"transformResponse":[null],"jsonpCallbackParam":"callback","url":"api/admin/users/create/","data":{"user":{"role":"user"}},"headers":{"Accept":"application/json, text/plain, */*","Content-Type":"application/json;charset=utf-8"}},"statusText":"OK","xhrStatus":"complete"}
However, when I give {{errors.login}}, the data is not displayed. Can I count on little help?
There's your problem. Login is not a property of the errors object but a sub property. It should be errors.data.records.login.

How to show Product Reviews in Product Details Information Template on SCA Aconcagua

I'm trying to show "Product Reviews" on product_details_information.tpl instead of product_details_full.tpl template. The reviews are not showing at all. I tried to add the product reviews as a child view to Product Details Information View without success. Here is the Product Reviews Module:
ProductReviews.js
/*
© 2017 NetSuite Inc.
User may not copy, modify, distribute, or re-bundle or otherwise make available this code;
provided, however, if you are an authorized user with a NetSuite account or log-in, you
may use this code subject to the terms that govern your access and use.
*/
// #module ProductReviews
// Defines the ProductReviews module (Model, Collection, Views, Router)
// Mount to App also handles rendering of the reviews
// if the current view has any placeholder for them
define('ProductReviews'
, [
'ProductReviews.Router'
, 'ProductReviews.Center.View'
, 'GlobalViews.StarRating.View'
, 'ProductDetails.Full.View'
,'ProductDetails.Information.View'
]
, function(
Router
, ProductReviewsCenterView
, GlobalViewsStarRatingView
, ProductDetailsFullView
, ProductDetailsInformationView
)
{
'use strict';
// #class ProductReviews #extends ApplicationModule
var ProductReviewsModule =
{
mountToApp: function (application)
{
if (SC.ENVIRONMENT.REVIEWS_CONFIG && SC.ENVIRONMENT.REVIEWS_CONFIG.enabled)
{
ProductDetailsFullView.addChildViews({
'ProductReviews.Center': function wrapperFunction (options)
{
return function ()
{
return new ProductReviewsCenterView({
item: options.model.get('item')
, application: options.application
});
};
}
});
ProductDetailsInformationView.addChildViews({
'ProductReviews.Center': function wrapperFunction (options)
{
return function ()
{
return new ProductReviewsCenterView({
item: options.model.get('item')
, application: options.application
});
};
}
});
ProductDetailsFullView.addChildViews({
'Global.StarRating': function wrapperFunction (options)
{
return function ()
{
return new GlobalViewsStarRatingView({
model: options.model.get('item')
, showRatingCount: true
, showSchemaInfo: true
});
};
}
});
ProductDetailsInformationView.addChildViews({
'Global.StarRating': function wrapperFunction (options)
{
return function ()
{
return new GlobalViewsStarRatingView({
model: options.model.get('item')
, showRatingCount: true
, showSchemaInfo: true
});
};
}
});
}
// default behavior for mount to app
return new Router(application);
}
};
return ProductReviewsModule;
});
and product_details_information.tpl
<div data-view="ProductReviews.Center"></div>
any thoughts on this?

How do I test with chai-as-promised a rejected promise and the error message?

I'm trying to check the error message on a rejected promise and if I make the message string wrong in the test it still passes.
MyService.doSomething({ id: 12345 }).should.eventually.be.rejectedWith(TypeError, 'no attr foo defined2');
svc.doSomething = function(thing){
var def = $q.defer();
if ( !thing.foo ) {
def.reject(new Error('no attr foo defined'));
} else {
def.resolve(thing);
}
return def.promise;
};
Update, it seems my tests are not working properly. When I return it times out:
it.only('should error', function(){
// todo this should fail but it just times out
return MyService.doSomething({ id: 12345 }).should.eventually.be.rejectedWith(TypeError, 'no attr foo defined2');
});
svc.doSomething = function(thing){
var def = $q.defer();
if ( !thing.foo ) {
def.reject(new Error('no attr foo defined'));
} else {
def.resolve(thing);
}
return def.promise;
};
Here's the error:
Error: timeout of 4000ms exceeded. Ensure the done() callback is being called in this test.
You are forgetting the eventually and the return before your call.!
return MyService.doSomething({ id: 12345 }).should.eventually.be.rejectedWith...

Unable to get my data from $firebaseObject using AngularFire in a controller. View/ng-repeat works fine

I have different sections in Firebase with normalized data, and I have routines to get the information, but I cannot loop through the returned records to get data. I want to use the keys in the $firebaseArray() to get data from other $firebaseObject().
GetOneTeam() .... {
var DataRef = GetFireBaseObject.DataURL(Node + '/'); // xxx.firebaseio.com/Schedules/
var OneRecordRef = DataRef.child(Key); // Schedule Key - 1
return $firebaseObject(OneRecordRef);
}
...
var Sched = GetOneSchedule('Schedules', 1);
... // For Loop getting data - Put in HomeId
var TeamRec = GetOneTeam('Teams', HomeId);
var Name = TeamRec.TeamName; // Does not TeamName value from Schedule/1
The following is more of the actual code in case the snippet above is not clear enough. Sample common routine for getting data:
angular.module('MyApp')
.constant('FIREBASE_URL', 'https://xxxxxxxx.firebaseio.com/');
angular.module('MyApp')
.factory('GetFireBaseObject', function(FIREBASE_URL) {
return {
BaseURL: function() {
return new Firebase(FIREBASE_URL);
},
DataURL: function(Node) {
return new Firebase(FIREBASE_URL + Node);
}
};
}
);
// Common code for getting Array/Object from Firebase.
angular.module('MyApp')
.factory("FireBaseData", ["$firebaseArray", "$firebaseObject", "GetFireBaseObject",
function($firebaseArray, $firebaseObject, GetFireBaseObject) {
return {
AllRecords: function(Node) {
var DataRef = GetFireBaseObject.DataURL(Node + '/');
return $firebaseArray(DataRef);
},
OneRecordAllChildren: function(Node, Key) {
var DataRef = GetFireBaseObject.DataURL(Node + '/');
var ParentRecordRef = DataRef.child(Key);
return $firebaseArray(ParentRecordRef);
},
OneRecord: function(Node, Key) {
var DataRef = GetFireBaseObject.DataURL(Node + '/');
var OneRecordRef = DataRef.child(Key);
return $firebaseObject(OneRecordRef);
},
AddRecord: function(Node, Record) {
var DataRef = GetFireBaseObject.DataURL(Node + '/');
var AddRecordRef = DataRef.child(Record.Key);
AddRecordRef.update(Record);
return $firebaseObject(AddRecordRef); // Return Reference to added Record
},
DeleteRecord: function(Node, Key) {
var DataRef = GetFireBaseObject.DataURL(Node + '/');
var DeleteRecordRef = DataRef.child(Key);
DeleteRecordRef.remove();
}
};
}
]);
Individual Controller's retrieval of records from firebase.io:
angular.module('MyApp').service("ScheduleData", ["FireBaseData",
function(FireBaseData) {
var DataPath = 'Schedules';
this.AllSchedules = function() {
return FireBaseData.AllRecords(DataPath);
};
this.AddSchedule = function(GameInfo) {
return FireBaseData.AddRecord(DataPath, GameInfo);
};
this.DeleteSchedule = function(GameKey) {
FireBaseData.DeleteRecord(DataPath, GameKey);
};
this.GetOneSchedule = function(GameKey) {
return FireBaseData.OneRecord(DataPath, GameKey);
};
}
]);
// Structure of a record, including named fields to come from another object (Team/Venue using the OneRecord FireBaseData call to get a $firebaseObject
angular.module('MyApp').factory("ScheduleRecord", function() {
return {
Clear: function(GameInfo) {
GameInfo.Key = "";
GameInfo.HomeTeamId = "";
GameInfo.HomeTeamName = "";
GameInfo.AwayTeamId = "";
GameInfo.AwayTeamName = "";
GameInfo.VenueId = "";
GameInfo.VenueName = "";
GameInfo.GameDate = "";
GameInfo.GameTime = "";
}
};
}
);
Controller module start:
angular.module('MyApp').controller('ScheduleCtrl', ["$scope", "ScheduleData", "ScheduleRecord", "TeamData", "VenueData",
function ($scope, ScheduleData, ScheduleRecord, TeamData, VenueData) {
var ClearEditData = function() {
$scope.ScheduleEditMode = false;
ScheduleRecord.Clear($scope.schedule);
};
var GameSchedules = ScheduleData.AllSchedules();
This next piece is where my question lies. Once the promise returns the static schedule list, I want to loop through each record and translate the Team Id (Home/Away) and Venue Id to the names.
GameSchedules.$loaded().then(function() {
angular.forEach(GameSchedules, function(GameInfo) {
var HomeTeam = TeamData.GetOneTeam(GameInfo.HomeTeamId);
GameInfo.HomeTeamName = HomeTeam.Name;
The GetOneTeam returns a $firebaseObject, based on the HomeTeamId child record. This returns null all the time.
This is the TeamData.GetOneTeam return using the FireBaseData as well.
angular.module('MyApp').service("TeamData", ["FireBaseData",
function(FireBaseData) {
var DataPath = 'Teams';
this.AllTeams = function() {
return FireBaseData.AllRecords(DataPath);
};
this.AddTeam = function(TeamInfo) {
return FireBaseData.AddRecord(DataPath, TeamInfo);
};
this.DeleteTeam = function(TeamKey) {
FireBaseData.DeleteRecord(DataPath, TeamKey);
};
this.GetOneTeam = function(TeamKey) {
return FireBaseData.OneRecord(DataPath, TeamKey);
};
}
]);
As I have a Firebase Object, how can I get my named data objects from the $firebaseObject?
This is a mess. Use $firebaseArray for collections, not $firebaseObject. Most of these strange wrapper factories are unnecessary. AngularFire services already have methods for add, remove, and so on, and all these factories attempt to make AngularFire into a CRUD model and don't actually provide any additional functionality or enhancements.
app.factory('Ref', function(FIREBASE_URL) {
return new Firebase(FIREBASE_URL);
});
app.factory('Schedules', function($firebaseArray, Ref) {
return $firebaseArray(Ref.child('Schedules'));
});
// or if you want to pass in the path to the data...
//app.factory('Schedules', function($firebaseArray, Ref) {
// return function(pathToData) {
// return $firebaseArray(Ref.child(pathToData));
// };
//});
app.factory('Schedule', function($firebaseObject, Ref) {
return function(scheduleId) {
return $firebaseObject(Ref.child('Schedules').child(scheduleId));
}
});
app.controller('...', function(Schedules, Schedule, Ref) {
$scope.newSchedule(data) {
Schedules.$add(data);
};
$scope.removeSchedule(key) {
Schedules.$remove(key);
};
$scope.updateSchedule(key, newWidgetValue) {
var rec = Schedules.$getRecord(key);
rec.widgetValue = newWidgetValue;
Schedules.$save(rec);
};
// get one schedule
var sched = Schedule(key);
sched.$loaded(function() {
sched.widgetValue = 123;
sched.$save();
});
});

Titanium Appcelerator HTTPClient return Array

i want to put the httpclient in a separate class and want to return the array of founded data.
My Code
function ServiceRequest(callback){
var data = [];
var xhr = Titanium.Network.createHTTPClient({
onload: function(e){
//Ti.API.info("Received text: " + this.responseText);
var doc = this.responseXML.documentElement;
var elements = doc.getElementsByTagName("record");
for (var r=0;r<elements.length;r++){
var name = elements.item(r).getElementsByTagName("field").item(3).textContent;
var monteur = elements.item(r).getElementsByTagName("field").item(15).textContent;
var adresse =elements.item(r).getElementsByTagName("field").item(10).textContent;
var ort = elements.item(r).getElementsByTagName("field").item(4).textContent +" - "+ elements.item(r).getElementsByTagName("field").item(5).textContent;
var date = elements.item(r).getElementsByTagName("field").item(8).textContent;
var termin
if (date !="") {
var arrayDate = date.split(".");
var newdate = arrayDate[1]+"."+arrayDate[0]+"."+arrayDate[2];
var temptermin = newdate +" - "+ elements.item(r).getElementsByTagName("field").item(9).textContent;
termin = temptermin;
};
data.push({"name":name,"monteur":monteur,"adresse":adresse,"ort":ort,"termin":termin});
callback( data );
};
},
onerror: function(e){
Ti.API.debug(e.error);
alert(e.error);
}
});
xhr.open("GET","http://theurltomyxml.com",false);
xhr.send();
}
module.exports =ServiceRequest;
the code snippet for my initialization
var ServiceRequest = require('ui/common/ServiceRequest');
request = new ServiceRequest(function(data){
});
Ti.API.info(request);
But the request is null, the array in my onLoad function is filled with data.
How can i wait until the httpRequest is ready than return the data array ?
You can use your custom function for callback like this way onload : callBack create your own callback function or you can put your callback( data ); after your forloop.
for (var r=0;r<elements.length;r++){//==your code here for parsing
}
callback( data );

Resources