Grunt j with regular expressions - regex

grunt.config('sass', {
options: {
sourceMap: true
},
dist: {
options: {
outputStyle: 'compact'
},
files: {
'/css/site.css': 'main/scss/site.scss',
'/css/template.home.css': 'main/scss/templates/home.scss'
'/css/template.contact.css': 'main/scss/templates/contact.scss'
'/css/template.something.css': 'main/scss/templates/something.scss'
}
}
});
is there is any way to handle this part nicely ( Thinking about a pattern but I' not sure about the possibility )
'/css/template.home.css': 'main/scss/templates/home.scss'
'/css/template.contact.css': 'main/scss/templates/contact.scss'
'/css/template.something.css': 'main/scss/templates/something.scss'

If you declare the config as a JS object you could do it like this:
var cfg = {
options: {
sourceMap: true
},
dist: {
options: {
outputStyle: 'compact'
},
files: {
'/css/site.css': 'main/scss/site.scss',
'/css/template.home.css': 'main/scss/templates/home.scss',
'/css/template.contact.css': 'main/scss/templates/contact.scss',
'/css/template.something.css': 'main/scss/templates/something.scss'
}
}
},
grunt = {
config: function() {
document.write('<br/><strong>grunt config set</string><br/>');
}
};
document.write('<br/>"files" before new config:<br/><br/>');
for (var property in cfg.dist.files) {
if (cfg.dist.files.hasOwnProperty(property)) {
document.write(property + ' = ' + cfg.dist.files[property] + '<br/>');
}
}
document.write('<br/>"files" after added config:<br/><br/>');
cfg.dist.files['/css/what ever...'] = 'the/latest/path';
for (var property in cfg.dist.files) {
if (cfg.dist.files.hasOwnProperty(property)) {
document.write(property + ' = ' + cfg.dist.files[property] + '<br/>');
}
}
grunt.config('sass', cfg);
Note the
cfg.dist.files['/css/what ever...'] = 'the/latest/path';
That's where the additional config is added.

Related

Cannot determine what is wrong with this action. Input Parameter is null

Using the following results in a null input error. Through debugging the plugin the input parameter is not being passed. Any ideas? I've done hundreds of these but never seen this type of issue.
tdn_GetFoxhoundNotesRequest = function (contactId) {
this.ContactId = contactId;
};
tdn_GetFoxhoundNotesRequest.prototype.getMetadata = function () {
return {
boundParameter: null,
parameterTypes: {
"ContactId": {
"typeName": "Edm.String",
"structurualProperty": 1
}
},
operationType: 0,
operationName: "tdn_GetFoxhoundNotes"
};
};
function LoadNotes(executionContext) {
var formContext = executionContext.getFormContext();
var contactId = formContext.data.entity.getId().replace("{", "").replace("}", "");
var request = new tdn_GetFoxhoundNotesRequest(contactId);
Xrm.WebApi.online.execute(request).then(
function success(result) {
if (result.ok) {
{
result.json().then(function (response) {
formContext.getAttribute("tdn_foxhoundnotestextblob").setValue(response.Notes);
formContext.getAttribute("tdn_foxhoundnotestextblob").setSubmitMode('never');
})
}
}
},
function (error) {
Xrm.Utility.alertDialog(error.message);
});
}

attributes are not defined with babel 6

I have an Ember app with ember-computed-decorators and I have this kind of model :
import DS from 'ember-data';
import {alias} from 'ember-computed-decorators';
export default DS.Model.extend({
#alias('customData.email') email
});
It worked with ember-cli-babel version 5 but I updated to the version 6 with tranform-decorator-legacy and I have this error :
email is not defined
I reproduced it with a simple js script like this :
function dec(target, name, descriptor) {
const method = descriptor.value;
descriptor.value = function(...args) {
return 'hello';
}
}
const Foo = {
#dec test
}
console.log(Foo.test);
And I have the same error.
This works :
function dec(target, name, descriptor) {
const method = descriptor.value;
descriptor.value = function(...args) {
return 'hello';
}
}
const Foo = {
#dec
test() {
return 'test';
}
}
console.log(Foo.test());
I think #dec test is strange but it worked with babel 5. What's the solution ?
Edit
Here is what's generated by ember :
define('tiny/models/subscription', ['exports', 'ember-data', 'ember-computed-decorators'], function (exports, _emberData, _emberComputedDecorators) {
function _createDecoratedObject(descriptors) { var target = {}; for (var i = 0; i < descriptors.length; i++) { var descriptor = descriptors[i]; var decorators = descriptor.decorators; var key = descriptor.key; delete descriptor.key; delete descriptor.decorators; descriptor.enumerable = true; descriptor.configurable = true; if ('value' in descriptor || descriptor.initializer) descriptor.writable = true; if (decorators) { for (var f = 0; f < decorators.length; f++) { var decorator = decorators[f]; if (typeof decorator === 'function') { descriptor = decorator(target, key, descriptor) || descriptor; } else { throw new TypeError('The decorator for method ' + descriptor.key + ' is of the invalid type ' + typeof decorator); } } } if (descriptor.initializer) { descriptor.value = descriptor.initializer.call(target); } Object.defineProperty(target, key, descriptor); } return target; }
exports['default'] = _emberData['default'].Model.extend(_createDecoratedObject([{
key: 'mail',
initializer: function initializer() {
return _emberData['default'].attr();
}
}, {
key: 'email',
decorators: [(0, _emberComputedDecorators.alias)('mail')],
initializer: function initializer() {
return email;
}
}]));
});
Here is what's generated by ember-cli-babel version 6 :
define('tiny/models/subscription', ['exports', 'ember-data', 'ember-computed-decorators'], function (exports, _emberData, _emberComputedDecorators) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {
var desc = {};
Object['ke' + 'ys'](descriptor).forEach(function (key) {
desc[key] = descriptor[key];
});
desc.enumerable = !!desc.enumerable;
desc.configurable = !!desc.configurable;
if ('value' in desc || desc.initializer) {
desc.writable = true;
}
desc = decorators.slice().reverse().reduce(function (desc, decorator) {
return decorator(target, property, desc) || desc;
}, desc);
if (context && desc.initializer !== void 0) {
desc.value = desc.initializer ? desc.initializer.call(context) : void 0;
desc.initializer = undefined;
}
if (desc.initializer === void 0) {
Object['define' + 'Property'](target, property, desc);
desc = null;
}
return desc;
}
var _dec, _desc, _value, _obj, _init;
exports.default = _emberData.default.Model.extend((_dec = (0, _emberComputedDecorators.alias)('mail'), (_obj = { email: email
}, (_applyDecoratedDescriptor(_obj, 'email', [_dec], (_init = Object.getOwnPropertyDescriptor(_obj, 'email'), _init = _init ? _init.value : undefined, {
enumerable: true,
configurable: true,
writable: true,
initializer: function initializer() {
return _init;
}
}), _obj)), _obj)));
});
I have the same result with babel 5.

Duplicate existing contacts alert

In Vtiger 6.5.0 open source, I wants to create a alert function to warn users that the conact's mobile is existing? could you please help me. I'm fresher.
Thanks,
Loi
You can refer the function wich exist in Account module for checking Duplicate Account Name.
Please follow this files you will get an idea.
This is the code flow how its done In Account Module
Registring Pre Save Event
http://code.vtiger.com/vtiger/vtigercrm/blob/master/layouts/vlayout/modules/Accounts/resources/Edit.js#L250
This teh Fucntion to check Duplicate in cache, If not calls the Helper function
http://code.vtiger.com/vtiger/vtigercrm/blob/master/layouts/vlayout/modules/Accounts/resources/Edit.js#L83
This the Helper function which makes the call to server
http://code.vtiger.com/vtiger/vtigercrm/blob/master/resources/helper.js#L166
This is the action function which is responsible for Serving the request which came from Helper Function
http://code.vtiger.com/vtiger/vtigercrm/blob/master/modules/Accounts/actions/CheckDuplicate.php#L30
And this is the function which checks for Duplicate
http://code.vtiger.com/vtiger/vtigercrm/blob/master/modules/Accounts/models/Record.php#L57
Hope this helps.
Hi Victor please follow this steps
modules\Leads\actions\Checkprimaryemail.php
<?php
class Leads_Checkprimaryemail_Action extends Vtiger_BasicAjax_Action {
public function checkPermission(Vtiger_Request $request) {
return;
}
public function process(Vtiger_Request $request) {
global $adb;
$moduleName = $request->get('module');
$recordId = $request->get('recordId');
$primary_email = $request->get('primary_email');
/*Lead Details*/
$lead_query = "select * from vtiger_leaddetails
inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_leaddetails.leadid
where vtiger_crmentity.deleted = 0 and vtiger_leaddetails.email='".$primary_email."'";
$lead_result = $adb->query($lead_query);
$lead_email = $adb->query_result($lead_result,0,'email');
$lead_numrows = $adb->num_rows($lead_result);
/*Contact Details*/
$cont_query = "select * from vtiger_contactdetails
inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_contactdetails.contactid
where vtiger_crmentity.deleted = 0 and vtiger_contactdetails.email='".$primary_email."'";
$cont_result = $adb->query($cont_query);
$cont_email = $adb->query_result($cont_result,0,'email');
$cont_numrows = $adb->num_rows($cont_result);
if($recordId != '' ){
if($primary_email == $lead_email && $lead_numrows == 1 ){
$emailtrue = 0;
} elseif($primary_email == $cont_email && $cont_numrows >= 1 ) {
$emailtrue = 1;
}
} else {
if(($lead_numrows >=1 || $cont_numrows >=1 ) || ($lead_numrows >=1 && $cont_numrows >= 1) ){
$emailtrue = 1;
} else {
$emailtrue = 0;
}
}
$emailData = array($emailtrue);
$response = new Vtiger_Response();
$response->setResult($emailData);
$response->emit();
}
}
?>
After Create One other file
layouts\vlayout\modules\Leads\resources\Edit.js
Vtiger_Edit_Js("Leads_Edit_Js", {
}, {
changeEvent: function (container) {
jQuery('input[name="email"]').on('focusout', function (e) {
var email = jQuery('input[name="email"]').val();
var recordId = jQuery('input[name="record"]').val();
var email_length = email.length;
if (email != '') {
if (email_length > 100) {
var errorMessage = app.vtranslate('JS_EMAIL_LENGTH_VALIDATION');
params = {
text: errorMessage,
'type': 'error',
};
Vtiger_Helper_Js.showMessage(params);
}
var progressIndicatorElement = jQuery.progressIndicator({
'position': 'html',
'blockInfo': {
'enabled': true
}
});
var postData = {
"module": 'Leads',
"action": "Checkprimaryemail",
"primary_email": email,
"recordId": recordId
}
AppConnector.request(postData).then(
function (data) {
progressIndicatorElement.progressIndicator({'mode': 'hide'});
if (data['result'] == 1) {
jQuery('#emailalready_exists').val(1);
var errorMessage = app.vtranslate('JS_EMAIL_EXIST');
params = {
text: errorMessage,
'type': 'error',
};
Vtiger_Helper_Js.showMessage(params);
} else {
jQuery('#emailalready_exists').val(0);
}
},
function (error, err) {}
);
e.preventDefault();
}
});
},
registerBasicEvents: function (container) {
this._super(container);
this.changeEvent(container);
}
});
To check duplicate records in vTiger follow below steps:
Register checkDuplicate function in registerBasicEvents
1: \layouts\vlayout\modules\Contacts\resources\Edit.js
getmobile : function(container){
return jQuery('input[name="mobile"]',container).val();
},
getRecordId : function(container){
return jQuery('input[name="record"]',container).val();
},
DuplicateCheck : function(form) {
var thisInstance = this;
if(typeof form == 'undefined') {
form = this.getForm();
}
jQuery( "#mobileFieldId" ).change(function() {
var mobile = thisInstance.getmobile(form);
var recordId = thisInstance.getRecordId(form);
var params = {
'module' : "Contacts",
'action' : "CheckDuplicate",
'mobile' : mobile,
'record' : recordId
}
AppConnector.request(params).then(
function(data) {
var response = data['result'];
var result = response['success'];
if(result == true) {
var message_params = {
title : app.vtranslate('JS_MESSAGE'),
text: response['message'],
animation: 'show',
type: 'error'
};
Vtiger_Helper_Js.showPnotify(message_params);
jQuery(".btn-success").attr('disabled',true);
return false;
} else {
jQuery(".btn-success").attr('disabled',false);
}
}
);
});
},
2: Create new file in** \modules\Contacts\actions\CheckDuplicate.php
Follow the same process / code as given in \modules\Accounts\actions\CheckDuplicate.php
3: Add new function checkDuplicate() in \modules\Contacts\models\Record.php
And follow same process as given in \modules\Accounts\models\Record.php having function checkDuplicate()
Note: Don't forget to change the db table name, class name module wise.
Hope this will help you. Thank you.

How to enableMajor?

How could I enable Major versioning on "Pages" list? My code is not working and I don't get any errors. Any suggestions?....
_spBodyOnLoadFunctionNames.push(onPageLoad());
function onPageLoad() {
ExecuteOrDelayUntilScriptLoaded(enableMajor, 'SP.js')
}
function enableMajor() {
var ctx = new SP.ClientContext.get_current();
var list = ctx.get_web().get_lists().getByTitle('Pages');
ctx.load(list);
ctx.executeQueryAsync(
function () {
list.enableMajor = true;
},
function (sender, args) {
console.log('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
);
}
UPDATE 06-15
====---------------
Major version will not set? i dont why it is not setted? Any suggestions?
<script>
var list;
function getPublishingPages(success, error) {
var ctx = SP.ClientContext.get_current();
list = ctx.get_web().get_lists().getByTitle('Pages');
var items = list.getItems(SP.CamlQuery.createAllItemsQuery());
ctx.load(items, 'Include(File)');
list.set_e
ctx.executeQueryAsync(function () {
success(items);
},
error);
}
SP.SOD.executeFunc('SP.js', 'SP.ClientContext', function () {
getPublishingPages(printPagesInfo, logError);
});
function printPagesInfo(pages) {
pages.get_data().forEach(function (item) {
var file = item.get_file();
var pageStatus = file.get_level() === SP.FileLevel.published ? 'published' : 'not published';
alert(String.format('Page {0} is {1}', file.get_name(), pageStatus));
list.set_enableVersioning(true);
list.update();
alert('Major versioning enabled');
});
}
function logError(sender, args) {
alert('An error occured: ' + args.get_message());
}
</script>
In order to enable Create major versions the following steps should be performed:
set SP.List.enableVersioning property to true
call SP.List.update Method to update the list
Example
function enableListVersioning(listTitle,success,error) {
var ctx = SP.ClientContext.get_current();
var list = ctx.get_web().get_lists().getByTitle(listTitle);
list.set_enableVersioning(true);
list.update();
ctx.executeQueryAsync(
function () {
success();
},
error);
}
//usage
enableListVersioning('Pages',
function(){
console.log('Versioning is enabled');
},
function(sender,args){
console.log('An error occured: ' + args.get_message());
});

How do I test an event has been broadcast in AngularJS?

I am just wondering how can I test the handleAddClientBroadcast event?
I have a navigation service like so:
angular.module("ruleManagement.services")
.factory('navigationService', function ($rootScope) {
var navigationService = {};
navigationService.prepForBroadcast = function() {
this.broadCastIsAddClientItem();
};
navigationService.broadCastIsAddClientItem = function() {
$rootScope.$broadcast('handleAddClientBroadcast');
};
return navigationService;
});
I inject this navigation service into my clientsCtrl and catch the handleAddClientBroadcast like so:
$scope.$on('handleAddClientBroadcast', function () {
$scope.clientModel = {
id: 0,
name: "",
description: "",
rules: []
};
var lastClient = _.findLast($scope.clients);
if (typeof lastClient == 'undefined' || lastClient == null) {
lastClient = $scope.clientModel;
}
$scope.clientModel.id = lastClient.id + 1;
$scope.clients.push($scope.clientModel);
});
Thanks.
Assuming you're using Jasmine
spyOn($rootScope, '$broadcast').andCallThrough();
...
expect($rootScope.$broadcast).toHaveBeenCalledWith('eventName');