Skip to content
This repository has been archived by the owner on Nov 29, 2023. It is now read-only.

Commit

Permalink
changed: dialogs can now be overridden in app
Browse files Browse the repository at this point in the history
changed: renamed enketo-config.json, translator.js, file-manager, widgets.js modules
  • Loading branch information
MartijnR committed Feb 14, 2018
1 parent bd72e66 commit 01b6a80
Show file tree
Hide file tree
Showing 19 changed files with 93 additions and 42 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ Change Log
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

[Unreleased]
[4.46.0]
---------------------
##### Added
- Full support for annotate widget.

##### Changed
- Draw/signature widget requires confirmation before reset.
- Modal dialogs can now be overridden in app
- Renamed 'enketo-config', 'translator', '../path/to/file-manager', and 'widgets' modules to 'enketo/config', 'enketo/translator', 'enketo/file-manager', 'enketo/widgets'. **WARNING: update overrides for these modules in your app!**

##### Fixed
- Printing: geo widget with appearance "maps" does not show coordinate fields.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Enketo Core [![npm version](https://badge.fury.io/js/enketo-core.svg)](http://badge.fury.io/js/enketo-core) [![Build Status](https://travis-ci.org/enketo/enketo-core.svg?branch=master)](https://travis-ci.org/enketo/enketo-core) [![Dependency Status](https://david-dm.org/enketo/enketo-core/status.svg)](https://david-dm.org/enketo/enketo-core) [![devDependency Status](https://david-dm.org/enketo/enketo-core/dev-status.svg)](https://david-dm.org/enketo/enketo-core?type=dev) [![Codacy Badge](https://www.codacy.com/project/badge/dc1c5aaa9267d75cbd2d6714d2b4fa32)](https://www.codacy.com/app/martijn_1548/enketo-core)
Enketo Core [![npm version](https://badge.fury.io/js/enketo-core.svg)](http://badge.fury.io/js/enketo-core) [![Build Status](https://travis-ci.org/enketo/enketo-core.svg?branch=master)](https://travis-ci.org/enketo/enketo-core) [![Dependency Status](https://david-dm.org/enketo/enketo-core/status.svg)](https://david-dm.org/enketo/enketo-core) [![devDependency Status](https://david-dm.org/enketo/enketo-core/dev-status.svg)](https://david-dm.org/enketo/enketo-core?type=dev) [[![Codacy Badge](https://api.codacy.com/project/badge/Grade/dc1c5aaa9267d75cbd2d6714d2b4fa32)](https://www.codacy.com/app/martijnr/enketo-core?utm_source=github.com&utm_medium=referral&utm_content=enketo/enketo-core&utm_campaign=Badge_Grade)
===============

The engine that powers [Enketo Smart Paper](https://enketo.org) and various third party tools including [these](https://enketo.org/about/adoption/).
Expand All @@ -12,7 +12,7 @@ Follow the [Enketo blog](http://blog.enketo.org) or [Enketo on twitter](https://
1. Install with `npm install enketo-core --save` or include as a git submodule.
2. Develop a way to perform an [XSL Transformation](https://enketo.org/develop/#transformation) on OpenRosa-flavoured XForms inside your app. The transformation will output an XML instance and a HTML form. See [enketo-transformer](https://github.com/enketo/enketo-transformer) for an available library/app to use or develop your own.
3. Add [themes](./src/sass) to your stylesheet build system (2 stylesheets per theme, 1 is for `media="print"`).
4. Override [config.json](./config.json) and optionally [widgets.js](./src/js/widgets.js) with your app-specific versions.
4. Override [the files under "browser"](./package.json), e.g. using [aliasify](https://www.npmjs.com/package/aliasify) with your app-specific versions.
5. Main methods illustrated in code below:

```javascript
Expand Down
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "enketo-core",
"description": "Extensible Enketo core containing the form logic engine and responsive form styling",
"homepage": "https://enketo.org",
"version": "4.45.0",
"version": "4.46.0",
"license": "Apache-2.0",
"os": [
"darwin",
Expand Down Expand Up @@ -58,9 +58,11 @@
"time-grunt": "1.x.x"
},
"browser": {
"enketo-config": "./config.json",
"widgets": "./src/js/widgets.js",
"translator": "./src/js/fake-translator"
"enketo/config": "./config.json",
"enketo/widgets": "./src/js/widgets.js",
"enketo/translator": "./src/js/fake-translator",
"enketo/dialog": "./src/js/fake-dialog",
"enketo/file-manager": "./src/js/file-manager"
},
"dependencies": {
"bootstrap-datepicker": "1.7.x",
Expand Down
2 changes: 1 addition & 1 deletion src/js/Form-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var utils = require( './utils' );
var $ = require( 'jquery' );
var Promise = require( 'lie' );
var FormLogicError = require( './Form-logic-error' );
var config = require( 'enketo-config' );
var config = require( 'enketo/config' );
var types = require( './types' );
var REPEAT_COMMENT_PREFIX = 'repeat:/';
var INSTANCE = /instance\(\s*(["'])((?:(?!\1)[A-z0-9.\-_]+))\1\s*\)/g;
Expand Down
4 changes: 2 additions & 2 deletions src/js/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ var FormModel = require( './Form-model' );
var $ = require( 'jquery' );
var Promise = require( 'lie' );
var utils = require( './utils' );
var t = require( 'translator' ).t;
var config = require( 'enketo-config' );
var t = require( 'enketo/translator' ).t;
var config = require( 'enketo/config' );
var inputHelper = require( './input' );
var repeatModule = require( './repeat' );
var pageModule = require( './page' );
Expand Down
33 changes: 33 additions & 0 deletions src/js/fake-dialog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';

var Promise = require( 'lie' );

/*
* This file is meant to be overidden with one that uses the app's dialogs.
*/

/**
* @param {String | {message: String, heading: String}} content Dialog content
*/
function alert( content ) {
window.alert( content );
return Promise.resolve();
}

/**
* @param {String | {message: String, heading: String}} content Dialog content
*/
function confirm( content ) {
return new Promise( function( resolve, reject ) {
if ( window.confirm( content ) ) {
resolve();
} else {
reject();
}
} );
}

module.exports = {
alert: alert,
confirm: confirm,
};
2 changes: 1 addition & 1 deletion src/js/file-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var Promise = require( 'lie' );
var $ = require( 'jquery' );
var utils = require( './utils' );
var fileManager = {};
var t = require( 'translator' ).t;
var t = require( 'enketo/translator' ).t;

/**
* Initialize the file manager .
Expand Down
2 changes: 1 addition & 1 deletion src/js/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

var $ = require( 'jquery' );
var Promise = require( 'lie' );
var config = require( 'enketo-config' );
var config = require( 'enketo/config' );

require( 'jquery-touchswipe' );

Expand Down
2 changes: 1 addition & 1 deletion src/js/repeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/

var $ = require( 'jquery' );
var config = require( 'enketo-config' );
var config = require( 'enketo/config' );
var disableFirstRepeatRemoval = config.repeatOrdinals === true;

module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion src/js/widgets-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var _setLangChangeListener;
var _setOptionChangeListener;
var _setValChangeListener;
var $ = require( 'jquery' );
var widgets = require( 'widgets' ).filter( function( widget ) {
var widgets = require( 'enketo/widgets' ).filter( function( widget ) {
return widget.selector;
} );

Expand Down
2 changes: 1 addition & 1 deletion src/widget/comment/commentwidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var Widget = require( '../../js/Widget' );
var $ = require( 'jquery' );
var pluginName = 'comment';
var t = require( 'translator' ).t;
var t = require( 'enketo/translator' ).t;

/**
* Visually transforms a question into a comment modal that can be shown on its linked question.
Expand Down
26 changes: 16 additions & 10 deletions src/widget/draw/draw-widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ var Widget = require( '../../js/Widget' );
var $ = require( 'jquery' );
var pluginName = 'drawWidget';
var support = require( '../../js/support' );
var fileManager = require( '../../js/file-manager' );
var fileManager = require( 'enketo/file-manager' );
var SignaturePad = require( 'signature_pad' );
var t = require( 'translator' ).t;
var t = require( 'enketo/translator' ).t;
var dialog = require( 'enketo/dialog' );

/**
* Widget to obtain user-provided drawings or signature.
Expand Down Expand Up @@ -246,14 +247,19 @@ DrawWidget.prototype._updateValue = function() {
};

DrawWidget.prototype._reset = function() {
if ( this.element.value && window.confirm( t( 'drawwidget.resetWarning' ) ) ) {
this.pad.clear();
this.cache = null;
delete this.element.dataset.loadedFileName;
this.element.dataset.filenamePostfix = '';
$( this.element ).val( '' ).trigger( 'change' );
// annotate file input
this.$widget.find( 'input[type=file]' ).val( '' ).trigger( 'change' );
var that = this;

if ( this.element.value ) {
dialog.confirm( t( 'drawwidget.resetWarning' ) )
.then( function() {
that.pad.clear();
that.cache = null;
delete that.element.dataset.loadedFileName;
that.element.dataset.filenamePostfix = '';
$( that.element ).val( '' ).trigger( 'change' );
// annotate file input
that.$widget.find( 'input[type=file]' ).val( '' ).trigger( 'change' );
} );
}
};

Expand Down
12 changes: 8 additions & 4 deletions src/widget/file/filepicker.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
'use strict';
var $ = require( 'jquery' );
var Widget = require( '../../js/Widget' );
var fileManager = require( '../../js/file-manager' );
var fileManager = require( 'enketo/file-manager' );
var utils = require( '../../js/utils' );
var pluginName = 'filepicker';
var t = require( 'translator' ).t;
var t = require( 'enketo/translator' ).t;
var TranslatedError = require( '../../js/translated-error' );
var dialog = require( 'enketo/dialog' );

/**
* FilePicker that works both offline and online. It abstracts the file storage/cache away
Expand Down Expand Up @@ -64,8 +65,11 @@ Filepicker.prototype._init = function() {

this.$widget
.find( '.btn-reset' ).on( 'click', function() {
if ( ( $input.val() || that.$fakeInput.val() ) && window.confirm( t( 'filepicker.resetWarning' ) ) ) {
$input.val( '' ).trigger( 'change' );
if ( ( $input.val() || that.$fakeInput.val() ) ) {
dialog.confirm( t( 'filepicker.resetWarning' ) )
.then( function() {
$input.val( '' ).trigger( 'change' );
} );
}
} )
.end();
Expand Down
4 changes: 2 additions & 2 deletions src/widget/geo-esri/geopicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
var $ = require( 'jquery' );
var Widget = require( '../../js/Widget' );
var support = require( '../../js/support' );
var config = require( 'enketo-config' );
var config = require( 'enketo/config' );
var convertor = require( './usng.js' );
var Promise = require( 'lie' );
var t = require( 'translator' ).t;
var t = require( 'enketo/translator' ).t;
var PLUGIN_NAME = 'esriGeopicker';
var OVERRIDE_PLUGIN_NAME = 'geopicker';
var DEFAULT_BASEMAPS = typeof config.arcGis === 'object' && Array.isArray( config.arcGis.basemaps ) ? config.arcGis.basemaps : [ 'streets', 'satellite', 'topo' ];
Expand Down
4 changes: 2 additions & 2 deletions src/widget/geo-esri/usng.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
if ( typeof console.warn === 'undefined' ) {
console.warn = console.log;
}
var dialog = require( 'enketo/dialog' );

//// ***************************************************************************
// * usng.js (U.S. National Grid functions)
Expand Down Expand Up @@ -341,7 +342,6 @@ var theClass = {
***************************************************************************/

LLtoUSNG: function( lat, lon, precision ) {
//alert("here");
lat = parseFloat( lat );
lon = parseFloat( lon );

Expand Down Expand Up @@ -804,7 +804,7 @@ var theClass = {
}

if ( usngStr.length < 7 ) {
alert( usngStr + " Appears to be a USNG string, but this application requires precision of at least 10,000 meters" );
dialog.alert( usngStr + " Appears to be a USNG string, but this application requires precision of at least 10,000 meters" );
return 0;
}

Expand Down
14 changes: 9 additions & 5 deletions src/widget/geo/geopicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

var $ = require( 'jquery' );
var Widget = require( '../../js/Widget' );
var config = require( 'enketo-config' );
var config = require( 'enketo/config' );
var L = require( 'leaflet' );
var Promise = require( 'lie' );
var t = require( 'translator' ).t;
var t = require( 'enketo/translator' ).t;
var support = require( '../../js/support' );
var dialog = require( 'enketo/dialog' );
var googleMapsScriptRequest;
var pluginName = 'geopicker';
var defaultZoom = 15;
Expand Down Expand Up @@ -173,8 +174,11 @@ Geopicker.prototype._init = function() {
this.$widget.find( '.btn-remove' ).on( 'click', function() {
if ( that.points.length < 2 ) {
that._updateInputs( [] );
} else if ( window.confirm( t( 'geopicker.removePoint' ) ) ) {
that._removePoint();
} else {
dialog.confirm( t( 'geopicker.removePoint' ) )
.then( function() {
that._removePoint();
} );
}
} );

Expand Down Expand Up @@ -763,7 +767,7 @@ Geopicker.prototype._updateDynamicMapView = function( latLng, zoom ) {
};

Geopicker.prototype._showIntersectError = function() {
window.alert( 'Borders cannot intersect!' );
dialog.alert( 'Borders cannot intersect!' );
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/widget/select-desktop/selectpicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
var $ = require( 'jquery' );
var Widget = require( '../../js/Widget' );
var support = require( '../../js/support' );
var t = require( 'translator' ).t;
var t = require( 'enketo/translator' ).t;
var pluginName = 'desktopSelectpicker';
require( '../../js/dropdown.jquery' );

Expand Down
4 changes: 2 additions & 2 deletions test/spec/form.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ describe( 'repeat functionality', function() {
} );

describe( 'ordinals are set for default repeat instances in the default model upon initialization', function() {
var config = require( 'enketo-config' );
var config = require( 'enketo/config' );
var dflt = config.repeatOrdinals;
beforeAll( function() {
config.repeatOrdinals = true;
Expand Down Expand Up @@ -1136,7 +1136,7 @@ describe( 'validation', function() {
var form;
var B = '[name="/data/b"]';
var C = '[name="/data/c"]';
var config = require( 'enketo-config' );
var config = require( 'enketo/config' );
var dflt = config.validateContinuously;

var setValue = function( selector, val ) {
Expand Down
2 changes: 1 addition & 1 deletion test/spec/formmodel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ describe( 'Repeat without ordinals', function() {
} );

describe( 'Ordinals in repeats', function() {
var config = require( 'enketo-config' );
var config = require( 'enketo/config' );
var dflt = config[ 'repeat ordinals' ];
var wr = '<root xmlns:enk="http://enketo.org/xforms">{{c}}</root>';
var wrt = '<root xmlns:jr="http://openrosa.org/javarosa" xmlns:enk="http://enketo.org/xforms">{{c}}</root>';
Expand Down

0 comments on commit 01b6a80

Please sign in to comment.