I use spine.js in conjunction with the Spine.Ajax Module to load stuff via JSON from the Server. I've probably run into some syncronisation problem. I have a sidebar which just binds to the refresh and change events and then is rendered:
Survey.bind 'refresh change', #render
I also have set up some routes, which display a survey when the user accesses it via #/survey/:id. This is my controller:
class App.Surveys extends Spine.Controller
className: 'surveys'
constructor: ->
super
#append(#sidebar = new App.Sidebar) # Sidebar to select surveys
#append(#surveys = new App.SurveysStack) # Show survey details survey
#routes
'/surveys/:id': (params) ->
#sidebar.active(params)
#surveys.show.active(params)
Survey.fetch()
As you see, Survey.fetch() is called after the initialization, which does not pose a problem to the sidebar. However, it seems, that it poses a problems to the surveys Show controller (which is called by a Spine.Stack called App.SurveyStack):
class Show extends Spine.Controller
constructor: ->
super
#active #change
change: (params) =>
# There is a bug! If Survey is not fetched when we run this,
# this throws an error.
#item = Survey.find(params.id)
#render()
render: ->
#html #view("surveys/show")(#item)
I keep getting errors from the commented part of the source: Uncaught Unknown record. Can I make the Survey.find() function block until Survey.fetch() is done?
You are correct in your diagnosis that you can't find an item before you've fetched it from the server.
The easiest solution is to bind an event to the Survey.fetch() call like so:
Survey.bind 'refresh change', #method_to_call
Let me know if that helps!
Actually the solution that worked for me is to initialize the Spine.Route.setup() after the object has refreshed. Instead of the standard call in app/index.js.coffee, it would be:
App.Survey.one 'refresh', ->
Spine.Route.setup()
Related
I'm a newbie on Joomla developing and I'm trying to fix an old administration module made by 'someone before me'. Module's been developed using MVC Components, it has several CRUDs and I'm stucked at deleting an item. The template view adds the toolbar icon like this:
JToolbarHelper::deleteList('', 'paises.delete', JTOOLBAR_DELETE);
It also has at the list controller (DistribuidoresControllerPaises), the getModel function:
public function getModel($name = 'Pais', $prefix = 'DistribuidoresModel', $config = array('ignore_request' => true))
{
$model = parent::getModel($name, $prefix, $config);
return $model;
}
The model class:
class DistribuidoresModelPais extends JModelAdmin
When selecting an item on the list, and clicking the trash button an empty page opens with this ending:
administrator/index.php?option=com_distribuidores&view=pais
If I come back to grid, the item still remains.
Any suggestion?
Thanks in advance
You can debug this by enabling debugging from Joomla configuration or you can try to to check with exit with in "delete" function of "paises" controller and can check you get item ids in post request or not.
Also you are using view "pais" also using model "pais" then why you are using "paises" controller for delete function, you should use "pais" controller to delete.
Also provide delete function which you are using to delete items, it may contain some issue.
Basically what i want is that in my view file i have a list of various restaurants,and in front of each of them is a "show" button,which on clicking should display three more buttons(dynamically),where each button performs some action regarding the corresponding restaurant name(like show menu,show reviews)(this action should be dynamic too). Can anybody help me with this implementation.
In the view you can place a link and a target container:
{{=A('the link', callback=URL('controller', 'function', args=[my_arg]), target="callback-target", _class="btn btn-default")}}
<div id="callback-target"></div>
If the link is clicked the function in controller is called and you can read the argument my_arg with:
def function():
data = request.args(0)
response.flash('Data received!')
return DIV('Return anything ...')
The returned data is displayed in <div id="callback-target"></div>
Im struggling to delete a view's instance. On view hbs i use each loop to show view hbs. On another field click i add a " . " to a json object, which then adds another field to the template.
>js>App.ApplicationView = Ember.View.extend({
anotherField: [{name: 'testname'}],
actions: {
moreFields: function(){
this.get('anotherField').pushObject({name: ''});
},
less: function(){
var counter = this.get('anotherField');
counter.shift();
this.set('anotherField', counter);
And hbs
{{#each view.anotherField}}
{{view Ember.TextField}}
{{/each}}
<button {{action 'moreFields' target='view'}}> ++ </button>
<button {{action 'less' target='view'}}> -- </button>
http://jsbin.com/iSUdiCaX/17/edit
Cheers
Kristjan
When you use the shift method Ember doesn't get notified that the anotherField property changed, and therefore it doesn't update the template. You can check this by adding this.rerender() at the end of the less action.
You could:
call this.propertyDidChange('anotherField') to notify the property changed: http://emberjs.com/api/classes/Ember.Object.html#method_propertyDidChange
use the slice method: http://emberjs.com/api/classes/Ember.Array.html#method_slice
var sliced = this.get('anotherField').slice(0, this.get('anotherField').length - 1);
this.set('anotherField' sliced);
I also noticed you're using the View to handle the actions whereas I believe the Controller would be a better place to do so.
EDIT
Well it depends.... I believe the controllers are a good place because they have knowledge of the model (the view also has it via the controller). if your anotherField property is only needed for displaying or event handling logic then I believe it is a good idea to leave it in the view. from docs
Views in Ember.js are typically only created for the following
reasons:
When you need sophisticated handling of user events
When you want to create a re-usable component
But if instead the anotherField property is used the held application state (user selections, needed for computed properties or other actions) then I believe it's better placed inside the controller (and therefore the actions modifying it).
Have in mind your view can handle one part of the action and send it to the controller:
actions: {
something: function() {
.....
this.get('controller').send('something') // calls send action in controller
}
}
I hope this helps!
Is it possible to use the Grails remoteFunction to call the create method on a child domain object?
I'm trying to call the create function in the child controller from a remoteFunction call on my gsp page, but keep getting an error
Message: Provided id of the wrong type for class XXX.YYY. Expected: class java.lang.Long, got class java.lang.String
And the remoteFunction code looks like so:
$.ajax({
type: 'POST',
url: "${remoteFunction(controller:'childController' action:'create' )}"
});
I've searched the Google all morning, and the only thing I can find is remoteFunctions for cascading a select statement.
Remember, the create method gives you the create gsp view. That view still has a save button on it which posts to the save controller method. I think you need to write a custom method that instantiates your new class and saves it all in one shot.
So what I have working so far is this:
<script type="text/javascript">
function someFunction(){
var id = ${parentInstance.id};
var $element = $('#elements ul li.selectedAdd');
$element.removeClass('selectedAdd');
$('#right-side ul').append($element);
${remoteFunction(
action:'createChild',
update:'right-side',
params:'\'id=\'+ escape(id) +\'&childType=\' + escape(childType)'
)}
};
Which works with this controller method:
def createChildBlock = {
def parent = Parent.get(params.id)
def childBlockInstance = new ChildBlock(childType:params.childType,parent:parent)
childBlockInstance = myService.saveChildBlock(parent,params)
render (template:"childBlock", model:[childBlockInstance:childBlockInstance])
}
And it works. Both domain objects are persisted to the database, and the view is updated. But, how can I keep the previous objects in the right-side div that is getting the update? Whenever I run the function, the previous child is removed and replaced with the new one, I just want to append the new one to the end of the list.
I have created a module in "Magento"in this module I have successfully added mutiple tab as tab appear on product page when we add a product(ex.general,inventory).
In my module I want to apply a feature on selected products.for this I want to show product listing as it as appear when we click on related product (When we add new product).
For this I did the same coding as it is on catalogue controller.
But still there is a error occur.
I have added following code on my controller page
public function relatedAction()
{
$gridBlock = $this->getLayout()->createBlock('customoption/adminhtml_edit_tab_related')
->setGridUrl($this->getUrl('*/*/gridOnly', array('_current' => true, 'gridOnlyBlock' => 'related')));
$iTemplateId = $this->getRequest()->getParam('template_id');$product2tpl = Mage::getResourceModel('customoption/customoption');
$productsArray = $product2tpl->getTemplateProducts($iTemplateId);
$serializerBlock = $this->_createSerializerBlock('links[related]', $gridBlock, $productsArray);
$this->_outputBlocks($gridBlock, $serializerBlock);
}
I have also extend the class Mage_Adminhtml_Controller_Action and following error occure when click on related tab.
"Call to a member function setGridUrl() on a non-object"
Please guide me where i am wrong.
Thanks in advance.