Tabulator - Using ajaxURLGenerator property - tabulator

I have a back end Url that can be used like this:
https://url/?pageNumber=1&pageSize=20&search=test
"pageNumber" and "pageSize" works flawless with the "paginationDataSent" property.
The "search" parameter should be the one used as a filter but I can't figure it out how to do it since tabulator build the url like this:
https://url/?pageNumber=1&pageSize=20&search%5B0%5D%5Bfield%5D=term_name&search%5B0%5D%5Btype%5D=like&search%5B0%5D%5Bvalue%5D=test
I know that I can change ajaxURLGenerator to make it work like I want but I can't figure it out.

I managed to do it, it is pretty straight forwarded actually.
Here's the code if anyone encounters this same question:
If you are going to use more parameters, just add them with more conditions.
ajaxURLGenerator: function (url, config, params) {
if (params.search[0] !== undefined)
return url + "?pageNumber=" + params.pageNumber + "&pageSize=" + params.pageSize + "&search=" + params.search[0].value
else
return url + "?pageNumber=" + params.pageNumber + "&pageSize=" + params.pageSize
},

Related

Using Filters in MS-Project Queries using Sharepoint API (PS.js / SP.js)

I'm trying to use the PS.js API to access information in Sharepoint, and I'm struggling to find a way to practically use the system.
In this case I'm trying to show upcoming resource allocation. I can easily get my hands on the list of all resources [ProjectContext.get_resources()], and from there the list of each of their assignments to projects/tasks [EnterpriseResource.get_assignments()]. But there are thousands of these, and I only want those that are booked on or after of the current date.
Is there any way I can create a filter or CAML view of these using the existing SP.js or PS.js, rather than reverting to the REST API?
I'd love if I could just modify the result of 'get_assignments' to add filter options, or add filters as arguments to 'load'. But I can't seem to find any documentation that tells me if it's possible.
Sample Below...
function ResourceListArrived(resource)
//Go through every Resource in the list
var rEnumerator = Resources.getEnumerator();
while (rEnumerator.moveNext()) {
var resource = rEnumerator.get_current();
$('#message').html('Processing Resource: ' + resource.get_name() + " / " + resource.get_id());
log('Investigating Resource ' + resource.get_name());
//Get the assignments for this resource.
GetResourceAssignments(resource);
}
$('#messageblock').fadeOut(500);
}
function GetResourceAssignments(resource)
{
var assignments = resource.get_assignments();
Project.load(assignments, 'Include(Start,Stop)');
//I'd like to filter THESE results somewhere in the previous 2x lines.
// Run the request on the server.
Project.executeQueryAsync(
function (sender, args) {
TotalRequestsOutstanding--;
var aEnumerator = assignments.getEnumerator();
while (aEnumerator.moveNext()) {
var assignment = aEnumerator.get_current();
log(' Assignment Found On ' + resource.get_name() + " - " + assignment.get_start());
}
},
function (sender, args) {
alert('Failed to get list of assignments. Error: ' + args.get_message());
});
}

UI Router query parameters and multiple states

I've been trying to get my head around query parameters with UI Router and think I have finally figured out why I'm having such a hard time with it. I'm building a small search app that has 2 states:
$stateProvider
.state('home', {
url: '/',
.state('search', {
url: '/search',
},
The home state has its own template (view) and so does the search state. They share the same controller. Basically all home state does is provide a search box to enter your search query or choose from autocomplete.
Once you have submitted your search query it goes to the search state via
$state.go('search');
I've tried many ways to get the user's search term(s) in the url on the search page using UI Router's query parameter syntax in the url: '/search?q' combined with $stateParams in the controller set as
vm.searchTerms = $stateParams.q || '';
I had switched it to $state.params.q but that didn't fix it.
I have successfully been able to get the query parameters in the url, however, when I do, it breaks search functionality. The autocomplete and query parameters work and display, but search function stops.
However, I think I finally understand why its not working the way I'd like it to. I believe it has to do with the fact that I'm using 2 states and not one parent state with a nested child state and that the templates are not nested - so $scope doesn't inherit. I'm getting close to this working... it transitions from the home state to the search state displaying query parameters in the search state's url... its simply that search breaks, but autocomplete and query parameters are working.
What I'm trying to achieve is to have the user enter search terms from the home state and then have results display in the search state along with query parameters in the url. Is there anything I need to do with home state or search state that I'm not doing?
OR
Is there anything in my search() in my controller that could be the problem
//search()
vm.search = function() {
//$state.go('search', {q: vm.searchTerms});
$state.go('search');
console.log(vm.searchTerms);
console.log('success - search');
vm.currentPage = 1;
vm.results.documents = [];
vm.isSearching = true;
return coreService.search(vm.searchTerms, vm.currentPage)
.then(function(es_return) {
console.log('success - return');
var totalItems = es_return.hits.total;
var totalTime = es_return.took;
var numPages = Math.ceil(es_return.hits.total / vm.itemsPerPage);
vm.results.pagination = [];
for (var i = 0; i <= 10; i++) {
console.log('success - for');
vm.results.totalItems = totalItems;
vm.results.queryTime = totalTime;
vm.results.pagination = coreService.formatResults(es_return.hits.hits);
vm.results.documents = vm.results.pagination.slice(vm.currentPage, vm.itemsPerPage);
console.log('success - documents');
}
vm.noResults = true;
}),
function(error){
console.log('ERROR: ', error.message);
vm.isSearching = false;
},
vm.captureQuery();
console.log('success - captureQuery');
};
You can add a parameter to your URL in two ways, use colon:
'url': '/search/:query'
or curly braces:
'url': '/search/{query}'
Then you can use the go method of $state with parameter to transition:
$state.go('search', {'query', 'foobar'});
You can access the parameter's value from your controller by using the params member of your $state object:
console.log($state.params.query);
or directly from the $stateParams object:
console.log($stateParams.query);
Reference: https://github.com/angular-ui/ui-router/wiki/URL-Routing#url-parameters

Option issue using chrome.storage.sync.get for first time user

chrome.storage.sync.get('savedItem', function (result) {
//some if else condition for result.savedItem here
myResult = result.savedItem;
});
$('p').val(myResult);
With above code, I got an undefined, because there is no setting been saved in my options page for the first time user. I tried to set a default value to myResult like if(result.savedItem == undefined) myResult = ''; but I still got undefined. Why?
2 issues at the same time.
1) You can set default for values not in the storage by providing a dictionary:
chrome.storage.sync.get({'savedItem' : 'myDefault'}, function (result) {
// result.savedItem is the saved value or 'myDefault'
});
2) The biggest issue is not understanding how asynchronous code works.
$('p').val(myResult); gets executed before myResult is assigned, because chrome.storage.sync.get returns immediately, with the function(result){...} being called later.
There have been tons of questions about that, take a look at, say, this and this.
Use chrome storage change - Refer this link
Example code:
chrome.storage.onChanged.addListener(function(changes, namespace) {
for (var key in changes) {
var storageChange = changes[key];
console.log('Storage key "%s" in namespace "%s" changed. ' + 'Old value was "%s", new value is "%s".', key, namespace, storageChange.oldValue, storageChange.newValue);
}
});

Re-using function inside jade

I have a inline script and code block repeated 2 times inside a .jade file and would like to:
re-use it. (i mean DRY it and have just one block/function)
escape the html like suggested here, right now I am using != linkExist('foo')
My idea was to use mixin, but don't know how to. My code works as is, but would like to know how to write it better. Thought about codereview (because my code actually works and I just want to improve it) but the jade has not even a tag there yet, so I think SO might be better.
h1 Teachers
for result in object.teachers
- var linkExist = function(i){
- if (result[i] != 'undefined'){
- var html = ', follow on ' + i + ': ' + result[i].split("http://")[1] + '';
- return html;
- };
- }
section
h3 #{result.Name}
p.inline #{result.Nick}
img(src=result.img)
p.small Location: #{result.Location}
p.small
| Web:
for webResult in result.Web
a(href=webResult,target='_blank') #{webResult.split('http://')[1]}
!= linkExist('Twitter')
!= linkExist('GitHub')
//now it repeats the code but for students
h1 Students
for result in object.students
- var linkExist = function(i){
//etc.......
You should be able to use a mixin; if you pass result as well, it should be pretty generic:
mixin linkExist(result, type)
if result[type] !== undefined
| , follow on #{type}: ...
//- use like this
for result in object.teachers
...
mixin linkExist(result, 'Twitter')
mixin linkExist(result, 'GitHub')
for result in object.students
...
mixin linkExist(result, 'Twitter')
mixin linkExist(result, 'GitHub')

Sharepoint > Which characters are *not* allowed in a list?

I've tried looking this up and haven't come up with the answer I'm looking for; I've found what cannot be included in filenames, folder names, and site names... but nothing on actual fields in a list.
I noticed that the percent symbol (%) is one that's not allowed in files/sites/folders. But it also doesn't populate when I try to pro grammatically add the fields to the list. I am doing this by using a small C# application that sends the data via Sharepoint 2010's built-in web services. I can manually enter the character, but it messes up each field in the row if I try it through code.
I've tried some of the escape characters that I've found via Google (_x26), but these don't seem to work either. Has anyone else had an issue with this? If these characters are allowed, how can I escape them when sending the data through a web service call?
Thanks in advance!
Justin
Any characters that aren't allowed when you enter a field name get encoded in the internal name. The format is a little different to what you show - try "_x0026_".
I usually avoid issues with weird internal names by creating the field with no spaces or special characters in the name, then renaming it. When you rename a field, only the display name changes and you keep the simple internal name.
Characters not allowed in SharePoint file name:
~, #, %, & , *, {, }, \, :, <, >, ?, /, |, "
Pasted from http://chrisbarba.com/2011/01/27/sharepoint-filename-special-characters-not-allowed/
Am I saying something weird when I state that there usually is a reason for certain characters not being allowed. I don't know which or why, but there probably is a reason.
Since you control which fields need to be there you can also dictate their (internal) names. I'd say follow best practice and name your fields using Camel case. And because you created them, you can just map the fields to the according fields in your data source.
As a follow on to #Elisa's answer, here's some JavaScript / TypeScript code that helps to prevent users from uploading files into SharePoint with invalid characters in the file name implemented on Nintex forms.
Here's the gist of the JavaScript version (note you'll have to obviously adapt for your own needs since this was designed for Nintex) :
//------------------------------------------------------------------------
//JavaScript Version:
//Code from http://cc.davelozinski.com/tips-techniques/nintex-form-tips-techniques/javascript-typescript-for-nintex-forms-to-validate-file-names
//------------------------------------------------------------------------
function validateAttachmentNames(eventObject) {
var textbox$ = NWF$(this);
var attachrowid = this.id.substring(10, 47);
var fileUploadid = attachrowid;
var index = attachrowid.substring(36);
//console.log('index:' + index);
//console.log('attachrowid:' + attachrowid);
//console.log('fileUploadid:' + fileUploadid);
if (index == '') {
attachrowid += '0';
}
var fileName = NWF.FormFiller.Attachments.TrimWhiteSpaces(textbox$.val().replace(/^.*[\\\/]/, ''));
var match = (new RegExp('[~#%\&{}+\|]|\\.\\.|^\\.|\\.$')).test(fileName);
if (match) {
isValid = false;
setTimeout(function () {
NWF$("tr[id^='attachRow']").each(function () {
var arrParts = (NWF$(this).find(".ms-addnew")[0]).href.split('"');
var fileName = arrParts[5];
var attachRow = arrParts[1];
var fileUpload = arrParts[3];
var match = (new RegExp('[~#%\&{}+\|]|\\.\\.|^\\.|\\.$')).test(fileName);
if (match) {
console.log(fileName);
NWF.FormFiller.Attachments.RemoveLocal(attachRow, fileUpload, fileName);
alert('Invalid file: ' + fileName + ' You cannot attach files with the following characters ~ # % & * { } \ : < > ? / + | \n\nThe file has been removed.');
}
});
}, 500);
}
}

Resources