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

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?

Related

Angularjs specific routing

Ok my fellow friends and associates,
I am trying to display only information based off of a url: parameter,
I have a service that has save a ton of data so I can use it across my application, but the problem I am having is displaying the data that I want to show based off of my parameter.
so here is my route, I am sending my id based off an link attribute
/CourseMaterials/:ID"
I have my service which stores all of my json objects to use accross the app.
angular.module('app').service('SaveService', function () {
this.textExpress = {};
this.courseMaterials = {};
this.courses = {};
this.student = {};
this.receipts = {};
this.webOrders = {};
return {
//This saves the textExpress object to reuse
getTextExpress: function () {
return this.textExpress;
},
setTextExpress: function (t) {
this.textExpress = t;
},
//This saves the courseMaterials object
getCourseMaterials: function () {
return this.courseMaterials;
},
setCourseMaterials: function (cm) {
this.courseMaterials = cm;
},
//This saves the courses object
get
Courses: function () {
return this.courses;
},
setCourses: function (c) {
this.courses = c;
},
//This saves the student object
getStudent: function () {
return this.student;
},
setStudent: function (s) {
this.student = s;
},
//This saves the receipts object
getReceipts: function () {
return this.receipts;
},
setReceipts: function (r) {
this.receipts = r;
},
//This saves the webOrders object
getWebOrders: function () {
return this.webOrders;
},
setWebOrders: function (wo) {
this.webOrders = wo;
},
}
});
I am a little stumped at how to say to my controller of my new view display only this info from my service
CourseMaterials/:id
So an object I might have looks like this
CourseMaterials[0] {
course: cit298,
author: ben stein,
isbn: xxxxxxxxxxxxxx,
}
CourseMaterials[1] {
course: cit298,
author: george stein,
isbn: xxxxxxxxxxxxxx,
}
On my new page I want to display something based off of the course applicable to what a user has selected based of the params in the link.
That looks like
http://localhost:55436/#!/CourseMaterials/cit%20298 etc......

Using an Array.prototype.forEach in AngularJS not updating to the view

I have a piece of code inside an angular controller that requests three services for data. Once the last service returns, I'm taking the data from all and merge it into a dataset. Out of the nested loops, my "vm" instance of this have the values I want the way I want (using a $log.debug to the console) but when I try to access in the view it has the value of initialization.
Here is my code:
function loadConfigs(userId) {
// Load the apps the user have access to
aimsApps.getAccessibleApps()
.then((resApps) => {
vm.apps = resApps.data;
// Load notifications types
aimsNotificationTypes.getNotificationTypes()
.then((resTypes) => {
vm.types = resTypes;
// Load the configurations for a user
aimsNotificationConfigs.getNotificationConfigs(userId)
.then((resConfigs) => {
vm.configs = resConfigs;
// Create a store like notification[app][type] and load the configs
$log.debug('ALL RESOLVED', vm.apps, vm.types, vm.configs);
vm.apps.forEach((eApp) => {
vm.notifSettings[eApp.name] = [];
vm.types.forEach((eType) => {
vm.configs.forEach((eConfig) => {
if ((eConfig.app === eApp.name) && (eConfig.notificationType === eType.name)) {
vm.notifSettings[eApp.name][eType.name] = eConfig;
} else {
vm.notifSettings[eApp.name][eType.name] = {
app: eApp.name,
user: userId,
notificationType: eType.name,
sendToWeb: true,
sendToEmail: true,
sendToSMS: true,
};
}
});
});
});
$log.debug('NOTIF CONFIG', vm.notifSettings);
});
});
});
}
When this line $log.debug('NOTIF CONFIG', vm.notifSettings); is reached, I can see in the console the values for vm.notifSettings but my view doesn't reflect those changes.
Any suggestions?

AngularJS. Return new factory instance

I'm a newbie in AngularJS and have faced the issue.
Can I reinject my factory singleton object across all controllers, where it's been injected?
For example:
.factory('medicalCenterService', function(MedicalCenterResource) {
var medicalCenterService = {};
medicalCenterService.currentMedCenter = MedicalCenterResource.get();
medicalCenterService.reloadMedCenter = function() {
medicalCenterService.currentMedCenter = MedicalCenterResource.get();
return medicalCenterService.currentMedCenter;
};
medicalCenterService.updateMedicalCenter = function(medicalCenter) {
MedicalCenterResource.updateMedicalCenter(medicalCenter);
medicalCenterService.currentMedCenter = medicalCenter;
};
return medicalCenterService;
})
In MedicalCenterController I get singleton object with medical center when application starts:
function MedicalCenterController($scope, medicalCenterService) {
$scope.currentMedCenter = medicalCenterService.currentMedCenter;
}
But later I try to edit medical center fields (name, address, etc..) in AccountProfileController
function AccountProfileController($scope, medicalCenterService) {
$scope.currentMedCenter = medicalCenterService.currentMedCenter;
$scope.applyMedCenterChanges = function (currentMedCenter) {
medicalCenterService.updateMedicalCenter(currentMedCenter);
};
}
And what I'm expecting to have is the object with updated fields.
How to return a new instance of my singleton?
Do you want something like this?
.factory('MedicalCenter', function(MedicalCenterResource) {
var MedicalCenter = function () {
var center = MedicalCenterResource.get(),
update = function() {
MedicalCenterResource.updateMedicalCenter(center)
};
return {
center: center,
update: update
}
};
return MedicalCenter;
})
function MedicalCenterController($scope, MedicalCenter) {
center = new MedicalCenter();
$scope.currentMedCenter = center.center;
}
function AccountProfileController($scope, MedicalCenter) {
center = new MedicalCenter();
$scope.currentMedCenter = center.center;
$scope.applyMedCenterChanges = function () {
center.update();
};
}
Like you wrote in post services are Singletons and its good way to share data over services. However if you want to create new instance of factory/service, you can't do that but we can create list of objects in one service/factory where each list item represents different instance. Something like:
.factory('medicalCenterService', function(MedicalCenterResource) {
var medicalCenterServices = [
{ctrlName: 'MedicalCenterController',medicalCenterService: {/*....*/}},
{ctrlName: 'AccountProfileController',medicalCenterService: {/*....*/}},
];
//......
})

In Backbone how can I remove models from a collection based on a filter/query?

I am using Backbonejs 0.9.2 with Titanium Alloy and I need to remove all the completed tasks from a Collection. Backbone.sync is configured to use a SQLite local database.
extendCollection: function(Collection) {
exts = {
self: this
, fetchComplete: function() {
var table = definition.config.adapter.collection_name
this.fetch({query:'SELECT * from ' + table + ' where complete=1'})
}
, removeComplete: function () {
this.remove(this.fetchComplete())
}
}
_.extend(Collection.prototype, exts);
return Collection
}
My Jasmine tests look like this
describe("task model", function () {
var Alloy = require("alloy"),
data = {
taskId: 77
},
collection,
item;
beforeEach(function(){
collection = Alloy.createCollection('task');
item = Alloy.createModel('task');
});
// PASSES
it('can fetch complete tasks', function(){
item.set(data);
item.save();
collection.fetchComplete();
expect(0).toEqual(collection.length);
item.markAsComplete();
item.save();
collection.fetchComplete();
expect(1).toEqual(collection.length);
});
// FAILS
it('can remove completed tasks', function(){
// we have 6 items
collection.fetch()
expect(6).toEqual(collection.length);
// there are no completed items
collection.fetchComplete();
expect(0).toEqual(collection.length);
item.set(data);
item.save();
item.markAsComplete();
item.save();
// we have 7 items 1 of which is complete
collection.fetch()
expect(7).toEqual(collection.length);
collection.removeComplete()
// after removing the complete item we should have 6 left
collection.fetch()
expect(6).toEqual(collection.length);
});
afterEach(function () {
item.destroy();
});
});
Iterate through your collection or use some of the helper functions via underscore and then call the remove function and pass in your model. See the docs here: http://backbonejs.org/#Collection-remove
Alternatively you can use underscores' _.filter method::
_.filter(tasks, function (task) {
return task.status == 'ACTIVE'
});
See this fiddle:
http://jsfiddle.net/Y3gPJ/

how can I update a model with custom idAttribute

in my simple backbone application, I am trying to update a model and every time it send a put request instead of post.
Well, this is my model named categoryModel
define(['Backbone'], function (Backbone) {
var CategoryModel = Backbone.Model.extend({
defaults: {
ID: '',
Name: 'Empty',
TagID: '0',
GID: '0'
},
idAttribute: "ID",
initialize: function () {
if (!this.get('Name')) {
this.set({ 'Name': this.defaults.Name });
}
}
});
return CategoryModel;
});
this is the collection
define(['Backbone','../../models/categories/categoryModel'], function (Backbone, categoryModel) {
var CategoryCollection = Backbone.Collection.extend({
url: '/parentcategory/Actions',
model: categoryModel
});
return new CategoryCollection;
});
here are my methods in the view
on a keychange event
createNewItem: function (e) {
var $this = $(e.currentTarget);
$('#selectedCategoryName').html($this.val());
//it creates a new model
globals.NewCategory = new CategoryModel({ Name: $this.val() });
}
on handleDrop event
handleDropEvent: function (event, ui) {
var draggable = ui.draggable;
//check if name has set
if (!globals.NewCategory) {
alert("Please write a category name");
$('#createNewCategory').focus();
return;
}
//get itemID
var itemID = draggable.attr("id").split('_')[1];
var itemDesc = draggable.attr("id").split('_')[0];
//check items category
if (itemDesc == "Tag") {
//check if tagID already exists
if (globals.NewCategory.TagID) {
alert("you have already specify a tag from this category");
return;
}
globals.NewCategory.set("TagID", itemID);
} else if (itemDesc == "gTag") {
if (globals.NewCategory.GID) {
alert("you have already specify a tag from this category");
return;
}
globals.NewCategory.set("GID", itemID);
}
categoriesCollection.create(globals.NewCategory, {
silent: true,
wait: true,
success: function (model, response) {
model.set("ID", response);
alert(model.id);
}
});
}
The categoriesCollection.create is called twice. Firstly for setting the TagID (on a success request it gets an ID ) and secondly for setting the GID.
Since the ID has been set, shouldn't had sent a POST request instead of PUT on the second call?
What am I doing wrong?
Thanks
The standard behaviour is to send a POST if the model is new ( doesn't have an ID attributed ) and send a PUT if the model id is set.
In your case it's working as designed, if you want it to use POST to send UPDATES you have to override Backbone.sync to work as you need, but I think it's easier for you to make your backend RESTful and create a PUT listener controller method for updates.
Another thing, if I got it right you are using create() to update models in your collection, I would advise you not to do that and instead use the save() directly in the model you want to update, the code will be a lot more readable.
Cheers.

Resources