Просмотр исходного кода

Import moment in web_form (#5106)

version-14
Faris Ansari 7 лет назад
committed by GitHub
Родитель
Сommit
e408de3abd
Не найден GPG ключ соответствующий данной подписи Идентификатор GPG ключа: 4AEE18F83AFDEB23
6 измененных файлов: 34 добавлений и 26 удалений
  1. +0
    -1
      frappe/public/build.json
  2. +1
    -1
      frappe/website/doctype/web_form/web_form.py
  3. +25
    -19
      frappe/website/js/web_form.js
  4. +1
    -0
      package.json
  5. +3
    -4
      rollup.config.js
  6. +4
    -1
      yarn.lock

+ 0
- 1
frappe/public/build.json Просмотреть файл

@@ -15,7 +15,6 @@
"public/js/frappe/misc/common.js", "public/js/frappe/misc/common.js",
"public/js/frappe/translate.js", "public/js/frappe/translate.js",
"public/js/frappe/misc/pretty_date.js", "public/js/frappe/misc/pretty_date.js",
"public/js/lib/moment/moment.min.js",
"public/js/lib/highlight.pack.js", "public/js/lib/highlight.pack.js",
"public/js/lib/microtemplate.js", "public/js/lib/microtemplate.js",
"public/js/frappe/query_string.js", "public/js/frappe/query_string.js",


+ 1
- 1
frappe/website/doctype/web_form/web_form.py Просмотреть файл

@@ -255,7 +255,7 @@ def get_context(context):


js_path = os.path.join(os.path.dirname(self.web_form_module.__file__), scrub(self.name) + '.js') js_path = os.path.join(os.path.dirname(self.web_form_module.__file__), scrub(self.name) + '.js')
if os.path.exists(js_path): if os.path.exists(js_path):
context.script = frappe.render_template(open(js_path, 'r').read().decode('utf-8'), context)
context.script = frappe.render_template(open(js_path, 'r').read(), context)


css_path = os.path.join(os.path.dirname(self.web_form_module.__file__), scrub(self.name) + '.css') css_path = os.path.join(os.path.dirname(self.web_form_module.__file__), scrub(self.name) + '.css')
if os.path.exists(css_path): if os.path.exists(css_path):


+ 25
- 19
frappe/website/js/web_form.js Просмотреть файл

@@ -1,3 +1,5 @@
import moment from 'moment';

frappe.ready(function() { frappe.ready(function() {
frappe.file_reading = false; frappe.file_reading = false;
frappe.form_dirty = false; frappe.form_dirty = false;
@@ -19,7 +21,7 @@ frappe.ready(function() {
if(input.files.length) { if(input.files.length) {
var file = input.files[0]; var file = input.files[0];
frappe.file_reading = true; frappe.file_reading = true;
reader.onload = function(e) {
reader.onload = function() {
input.filedata = { input.filedata = {
"__file_attachment": 1, "__file_attachment": 1,
"filename": file.name, "filename": file.name,
@@ -30,14 +32,14 @@ frappe.ready(function() {
(frappe.max_attachment_size * 1024 * 1024)) { (frappe.max_attachment_size * 1024 * 1024)) {
frappe.msgprint(__('Max file size allowed is {0}MB', frappe.msgprint(__('Max file size allowed is {0}MB',
[frappe.max_attachment_size])); [frappe.max_attachment_size]));
input.filedata = null
input.filedata = null;


// clear attachment // clear attachment
$(input).val(''); $(input).val('');
$(input).attr('data-value', ''); $(input).attr('data-value', '');
} }
frappe.file_reading = false; frappe.file_reading = false;
}
};


reader.readAsDataURL(file); reader.readAsDataURL(file);
} }
@@ -48,7 +50,7 @@ frappe.ready(function() {
if($(input).attr('data-reqd')) { if($(input).attr('data-reqd')) {
$(input).parent().toggleClass('has-error', !!!$(input).val()); $(input).parent().toggleClass('has-error', !!!$(input).val());
} }
}
};


// show mandatory fields as red // show mandatory fields as red
$('.form-group input, .form-group textarea, .form-group select').on('change', function() { $('.form-group input, .form-group textarea, .form-group select').on('change', function() {
@@ -61,7 +63,9 @@ frappe.ready(function() {
if(maxlength && (($(this).val() || '') + '').length > maxlength-1) { if(maxlength && (($(this).val() || '') + '').length > maxlength-1) {
$(this).val($(this).val().substr(0, maxlength-1)); $(this).val($(this).val().substr(0, maxlength-1));
} }
}).each(function() { set_mandatory_class(this); });
}).each(function() {
set_mandatory_class(this);
});


// if changed, set dirty flag // if changed, set dirty flag
$form.on('change', function() { $form.on('change', function() {
@@ -118,7 +122,7 @@ frappe.ready(function() {
.removeClass('hidden') .removeClass('hidden')
.find(':input:first').focus(); .find(':input:first').focus();


}
};


// add row // add row
$('.btn-add-row').on('click', function() { $('.btn-add-row').on('click', function() {
@@ -170,7 +174,9 @@ frappe.ready(function() {


// set name of child record (if set) // set name of child record (if set)
var name = $(this).attr('data-name'); var name = $(this).attr('data-name');
if(name) { d.name = name; }
if(name) {
d.name = name;
}


// check if child table has value // check if child table has value
var has_value = false; var has_value = false;
@@ -195,7 +201,7 @@ frappe.ready(function() {
}); });


return doc; return doc;
}
};


// get data from input elements // get data from input elements
// for the given doctype // for the given doctype
@@ -205,32 +211,32 @@ frappe.ready(function() {
var $input = $(this); var $input = $(this);
var input_type = $input.attr("data-fieldtype"); var input_type = $input.attr("data-fieldtype");
var no_attachment = false; var no_attachment = false;
var val;
if(input_type==="Attach") { if(input_type==="Attach") {
// save filedata dict as value // save filedata dict as value
if($input.get(0).filedata) { if($input.get(0).filedata) {
var val = $input.get(0).filedata;
val = $input.get(0).filedata;
} else { } else {
// original value // original value
var val = $input.attr('data-value');
val = $input.attr('data-value');
if (!val) { if (!val) {
val = {'__no_attachment': 1}
val = {'__no_attachment': 1};
no_attachment = true; no_attachment = true;
} }
} }
} else if(input_type==='Text Editor') { } else if(input_type==='Text Editor') {
var val = $input.parent().find('.note-editable').html();
val = $input.parent().find('.note-editable').html();
} else if(input_type==="Check") { } else if(input_type==="Check") {
var val = $input.prop("checked") ? 1 : 0;
val = $input.prop("checked") ? 1 : 0;
} else if(input_type==="Date") { } else if(input_type==="Date") {
// convert from user format to YYYY-MM-DD // convert from user format to YYYY-MM-DD
if($input.val()) { if($input.val()) {
var val = moment($input.val(), moment.defaultFormat).format('YYYY-MM-DD');
val = moment($input.val(), moment.defaultFormat).format('YYYY-MM-DD');
} else { } else {
var val = null;
val = null;
} }
} else { } else {
var val = $input.val();
val = $input.val();
} }


if(typeof val==='string') { if(typeof val==='string') {
@@ -246,7 +252,7 @@ frappe.ready(function() {
out[$input.attr("name")] = val; out[$input.attr("name")] = val;
}); });
return out; return out;
}
};


function save(for_payment) { function save(for_payment) {
if(window.saving) if(window.saving)
@@ -398,7 +404,7 @@ frappe.ready(function() {
timeFormat: "hh:ii:ss" timeFormat: "hh:ii:ss"
}); });
} }
}
};


setup_date_picker($form); setup_date_picker($form);




+ 1
- 0
package.json Просмотреть файл

@@ -19,6 +19,7 @@
"cookie": "^0.3.1", "cookie": "^0.3.1",
"express": "^4.16.2", "express": "^4.16.2",
"frappe-datatable": "frappe/datatable", "frappe-datatable": "frappe/datatable",
"moment": "^2.20.1",
"redis": "^2.8.0", "redis": "^2.8.0",
"showdown": "^1.8.6", "showdown": "^1.8.6",
"socket.io": "^2.0.4", "socket.io": "^2.0.4",


+ 3
- 4
rollup.config.js Просмотреть файл

@@ -101,10 +101,9 @@ function get_js_config(output_file, input_files) {
file: path.resolve(assets_path, output_file), file: path.resolve(assets_path, output_file),
format: 'iife', format: 'iife',
name: 'Rollup', name: 'Rollup',
// globals: {
// 'sortablejs': 'window.Sortable',
// 'clusterize.js': 'window.Clusterize'
// },
globals: {
'jquery': 'window.jQuery'
},
sourcemap: true sourcemap: true
}, },
context: 'window', context: 'window',


+ 4
- 1
yarn.lock Просмотреть файл

@@ -615,7 +615,6 @@ frappe-datatable@frappe/datatable:
resolved "https://codeload.github.com/frappe/datatable/tar.gz/99701f2477b3fb8180ccafaf2c2746886b13ba53" resolved "https://codeload.github.com/frappe/datatable/tar.gz/99701f2477b3fb8180ccafaf2c2746886b13ba53"
dependencies: dependencies:
clusterize.js "^0.18.0" clusterize.js "^0.18.0"
lodash "^4.17.5"
sortablejs "^1.7.0" sortablejs "^1.7.0"


fresh@0.5.2: fresh@0.5.2:
@@ -1106,6 +1105,10 @@ mkdirp@^0.5.0:
dependencies: dependencies:
minimist "0.0.8" minimist "0.0.8"


moment@^2.20.1:
version "2.20.1"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.20.1.tgz#d6eb1a46cbcc14a2b2f9434112c1ff8907f313fd"

ms@2.0.0: ms@2.0.0:
version "2.0.0" version "2.0.0"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"


Загрузка…
Отмена
Сохранить