we have written custom doclib action in document library.we are using alfresco 5.x;when the custom link is clicked then "onManifestAsset" action is getting called when it failed then it should prompt popup window with ok and cancel buttons.when i click ok button then another ajax call is not getting called.
YAHOO.Bubbling.fire("registerAction",
{
actionName: "onManifestAsset",
fn: function onManifestAsset(file) {
this.modules.actions.genericAction(
{
success:
{
message: this.msg("success")
},
failure:
{
callback :
{
scope: this,
fn: function(object)
{
Alfresco.util.PopupManager.displayPrompt(
{
text: "Your zip file does not include a metadata spreadsheet;",
buttons: [
{
text: "Ok",
handler: function()
{
this.destroy();
console.log("...start::::::it is normal zip without meta data template:")
//its coming here but below ajax is not getting called when I click ok button
Alfresco.util.Ajax.request(
{
url: Alfresco.constants.PROXY_URI+"xxxxx/manifestZIP?nodeRef="+file.nodeRef,
method: "GET",
successCallback:
{
fn: function dlA_onActionDetails_refreshSuccess(response) {
Alfresco.util.PopupManager.displayMessage({
text: "Success"
});
},
scope: this
},
failureMessage: this.msg("message.delete.failure", ".......")
});
}
},
{
text: "Cancel",
handler: function()
{
this.destroy();
},
isDefault: true
}
]
});
}
}
},
webscript:
{
name: "xxxx/extractAsset?nodeRef={nodeRef}",
stem: Alfresco.constants.PROXY_URI,
method: Alfresco.util.Ajax.GET,
params:
{
nodeRef: file.nodeRef
}
},
config:
{
}
});
}
})
Related
How to pass json object to WebApi as GET using $resource in angular?
My service:
pmsService.factory('Widgets', ['$resource', function ($resource) {
var data = $resource('/api/:path/:id', {
path: '#path'
}, {
getWidgets: {
params: { path: 'widgets' },
method: "GET",
isArray: true
},
getWidget: {
params: { path: 'widgets' },
method: "GET",
isArray: false
},
getWidgetData: {
params: { path: 'widgets' },
method: "POST"
},
});
return data;
In angular controller:
Widgets.getWidgetData({ id: $scope.widget.id}, $scope.paramValues ).$promise.then(function (data) {
$scope.widget.Data = data;
$log.debug($scope.widget.Data);
});
In Controller:
[Route("api/widgets/{id}")]
[HttpPost]
public Object Get(int id, dynamic prms)
{
....
}
This should sends 2 parameters to WebApi Controller, id and list of parameters for the Widget. Fiddler shows:
/api/widgets/31/%5Bobject%20Object%5D
So routing works correctly, but the object prms I received is empty.
I don't really understand what you're trying to do there but
if you're trying to achieve a url parameter as in /api/widgets/31?foo=bar, then this is how I would do it.
angular
.module('myMod', ['$resource'])
.factory('Widgets',
['$resource', function ($resource) {
return $resource(
'/api/:path/:id/',
{'path': '#path'},
{
getWidgets: {
params: {path: 'widgets'},
method: "GET",
isArray: true
},
getWidget: {
params: {path: 'widgets'},
method: "GET",
isArray: false
},
getWidgetData: {
params: {path: 'widgets'},
method: "GET",
isArray: false
}
})
}])
.controller('WidgetsController',
['$scope', 'Widgets', function ($scope, Widgets) {
$scope.widget = Widgets.getWidget({
id: 1,
foo: 'bar'
});
}]);
That would a make GET request to /api/widgets/1?foo=bar. You can include a nested object or an array like this and it will be serialised and appended to the url
// In controller
.controller('WidgetsController',
['$scope', 'Widgets', function ($scope, Widgets) {
$scope.widget = Widgets.getWidget({
id: 1,
fields: ['name', 'price']
});
}]);
This would make a GET request to /api/widgets/1?fields=name&fields=price.
I usually prefer to use the $httpParamSerializerJQLike serializer to serialize the parameters in this form /api/widgets/1?fields[]=name&fields[]=price which in my experience is less problematic. To use this serializer, you need to configure $http like so
angular
.module('myMod')
.config(['$httpProvider', function ($httpProvider) {
$httpProvider.defaults.paramSerializer = '$httpParamSerializerJQLike';
}])
Hope that helps
I currently have a problem with data not being ready upon full page refreshes. I get the following error
TypeError: Cannot read property 'earnings' of undefined
However, the data gets loaded correctly when I transition to the route through a pathFor link from another template.
I have the following route defined:
this.route('overview', {
path: '/overview',
layoutTemplate: 'dashboardLayout',
loginRequired: 'entrySignIn',
waitOn: function() {
Meteor.subscribe('overviewData');
},
data: function() {
return {
earnings: Meteor.user().earnings,
};
},
onAfterAction: function() {
SEO.set({
title: 'Overview | ' + SEO.settings.title
});
}
});
Which subscribes to this publication:
Meteor.publish('overviewData', function() {
if (!this.userId) { return null; }
return [
Meteor.users.find(this.userId, { fields: { earnings: 1} }),
Tabs.find({ userId: this.userId })
];
});
Piece of template referencing data:
<div class="period pull-left">
Period <span class='amount'>{{earnings.period}}</span>$
</div>
Try this.ready() before sending data, and also add return in waitOn function
try the following code
this.route('overview', {
path: '/overview',
layoutTemplate: 'dashboardLayout',
loginRequired: 'entrySignIn',
waitOn: function() {
return Meteor.subscribe('overviewData');
},
data: function() {
if(this.ready()){
return {
earnings: Meteor.user().earnings,
}
}
},
onAfterAction: function() {
SEO.set({
title: 'Overview | ' + SEO.settings.title
});
}
});
EDIT
This works because this.ready() will be true only after the subscriptions which are returned by waitOn() function completed.
In your code your sending the data without checking whther the data is subscribed or not(or the data is sent to client or not). So it return undefined
I think this may be caused by the fact that it takes a moment for the browser to read the cookie data to log back in. Maybe try adding an onBeforeAction for your route that checks if the user is logging in before rerouting.
this.route('overview', {
path: '/overview',
layoutTemplate: 'dashboardLayout',
loginRequired: 'entrySignIn',
waitOn: function() {
Meteor.subscribe('overviewData');
},
data: function() {
return {
earnings: Meteor.user().earnings,
};
},
onBeforeAction: function() {
if (!Meteor.user()) {
if (Meteor.loggingIn())
this.render('loadingTemplate');
}
else {
this.next();
}
},
onAfterAction: function() {
SEO.set({
title: 'Overview | ' + SEO.settings.title
});
}
});
Meteor users are a reactive data source, so the route should run again when loggingIn() is finished and shouldn't throw an undefined error.
I have publish code on server-side:
Meteor.publish("getChannelsList", function() {
return News.find({ }, { title: 1 });
});
And subscriptions.js on client:
Meteor.subscribe("getChannelsList", function(err, res) {
if (err) {
throw new Meteor.Error("Subscription error", "Exception in Meteor.subscribe method", err);
}
return res;
});
Collection in it's own "collections" directory
News = new Meteor.Collection("newsStock");
This is my template helper:
Template.channel.helpers({
channels: function() {
return News.find({ }, { title: 1 });
}
});
Autopublish and insecure were removed.
I'm waiting on client database object with "title" and "id" only. If I do in browser debugger News.find().pretty() why I see whole object, with all fields? Removing autopublish is not affect for me.
Can I do multiple publications and subscribes and how it's works?
If you're only intending to return the title, it should be:
Template.channel.helpers({
channels: function() {
return News.find({ }, {
fields: {
title: 1
}
});
}
});
As you point out, this will also publish the _id by default.
I use JSON to load Full Calendar and include a description for each event in a custom parameter. I want to use jQuery dialog box on eventClick function but don't know how to specify it. Here is what I'm trying to do:
eventClick: function(calEvent, jsEvent, view) {
$("#cal_event").dialog({
title: calEvent.title,
content: calEvent.description
});
}
Is there an Object to use where I have indicated "content"? If not, how do I get the calEvent.description into the dialog box?
Thanks for any help you can offer.
Thought I'd post how I ended up doing this to help others reading this post.
I used the following:
$(document).ready(function() {
$('#calendar').fullCalendar({
theme: "true",
aspectRatio: 1.8,
weekMode: 'liquid',
header: {
left: "",
center: "prev title next",
right: ""
},
buttonIcons:{
prev: "triangle-1-w",
next: "triangle-1-e"
},
eventSources: [
{
url: 'file1.php', // Event Source One //
type: 'POST',
error: function() {
alert('there was an error while fetching events!');
},
color: '#006600',
textColor: 'white'
},
{
url: 'file2.php', // Event Source Two //
type: 'POST',
error: function() {
alert('there was an error while fetching events!');
},
borderColor: '#006600',
color: 'white',
textColor: '#333333'
}
],
eventClick: function(calEvent, jsEvent, view) {
$("#dialog_frame").css("visibility", "visible");
$("#dialog_frame").draggable("enable");
$(".dialog_content").html(calEvent.description);
$(".dialog_title").html(calEvent.title);
}
})
});
I'm having trouble in validating a jQuery UI dialog using Jquery Validate upon clicking Save.
Here's my code to create Jquery dialog. It loads the dialog from a target a href URL:
$(document).ready(dialogForms);
function dialogForms() {
$('a.dialog-form').click(function() {
var a = $(this);
$.get(a.attr('href'),function(resp){
var dialog = $('<div>').attr('id','formDialog').html($(resp).find('form:first').parent('div').html());
$('body').append(dialog);
dialog.find(':submit').hide();
dialog.find('#return').hide();
dialog.dialog({
title: a.attr('title') ? a.attr('title') : '',
modal: true,
buttons: {
'Save': function() {submitFormWithAjax($(this).find('form'));},
'Cancel': function() {$(this).dialog('close');}
},
close: function() {$(this).remove();},
width: 'auto'
});
}, 'html');
return false;
});
}
function submitFormWithAjax(form) {
form = $(form);
$.ajax({
beforeSend: function(data) {
//alert("beforesend");
form.validate();
},
url: form.attr('action'),
data: form.serialize(),
type: (form.attr('method')),
dataType: 'text',
error: function(data) {
alert(data);
$('#result').html(data);
},
success: function(data) {
//alert("success");
$('#result').html(data);
setTimeout("reloadPage()", 500);
}
});
return false;
}
The beforeSend is called, but it doesn't seem to call the validate method, which is located on the parent page from which Dialog is called.
$(document).ready(function() {
$("#event_form").validate({
rules: {
Name: {
required: true
},
Category: {
required: true
}
},
messages: {
Name: "Please enter an event name",
Category: "Please choose a category"
},
submitHandler: function(form) {
alert("validated");
// $('#loading_1').show();
// $('#proceed_c').hide();
// $(form).ajaxSubmit();
// //form.submit();
},
errorPlacement: function(error, element) {
error.appendTo(element.next(".status"));
}
});
}
Is the problem with the beforeSend within submitFormWithAjax function, the location of $("#event_form").validate or the submitHandler: function(form) within it? Any help will be greatly appreciated.
When you initialize the jQueryUI dialog, it modifies the DOM, the whole dialog is taken out of it's location in the page and inserted right before the </body> tag. You can see this with Firebug. This causes a problem for Validate, because now the form is empty. To solve this, on the dialog's open event, append it to the form. It sounds really wacky, but trust me, it works :)
dialog.dialog({
title: a.attr('title') ? a.attr('title') : '',
modal: true,
buttons: {
'Save': function() {submitFormWithAjax($(this).find('form'));},
'Cancel': function() {$(this).dialog('close');}
},
close: function() {$(this).remove();},
open: function(){
$(this).parent().appendTo($('#event_form'));
},
width: 'auto'
});
Edit:
<form id='event_form'>
<div id="dialog" title="DialogTitle">
</div>
</form>
Took a slightly different approach to this. I needed to reuse my modal form so I append it once jquery "creates" the modal:
$("#mdl_Subject").dialog({
autoOpen: false,
show: "drop",
hide: "drop",
modal: true,
create: function () {
$(this).parent().appendTo($('#aspnetForm'));
}
});