v/pol
1
0
mirror of https://github.com/taroved/pol synced 2025-05-28 03:50:08 -07:00

xpath editor in progress

This commit is contained in:
Alexandr Nesterenko 2017-08-03 20:52:31 +00:00
parent 84c6b96838
commit afd10fdf6d
6 changed files with 41 additions and 13 deletions

View File

@ -93,7 +93,7 @@ msgstr "Предпросмотр"
#: templates/frontend/setup.html:46
msgid "xpath.link"
msgstr ""
msgstr "http://zvon.org/xxl/XPathTutorial/Output_rus/examples.html"
#: templates/frontend/setup.html:54
msgid "setup.you_are_creating_feed_with"

View File

@ -161,5 +161,6 @@ def build_xpathes_for_items(item_tag_ids, html_json):
item_xpathes[name] = '/'.join([repr(path_item) for path_item in selection_pathes[name]])
else:
item_xpathes[name] = '.'
item_xpathes[name] += '/child::node()'
return [feed_xpath, item_xpathes]

View File

@ -37,25 +37,37 @@ function check_pathes(pathes) {
var _config = ['', {}];
var _active = false;
var _validated = false;
function updateSelector(name, messages) {
var control_group = $('#ste-'+ name).parent().parent();
var help_text = control_group.find('.help-inline');
if ('error' in messages) {
control_group.removeClass('info').addClass('error');
help_text.text(messages['error']);
}
else {
else if ('count' in messages || $('#ste-'+ name).val().trim()) {
if (!('count' in messages))
messages['count'] = 0;
control_group.removeClass('error').addClass('info');
help_text.text(help_text.attr('count-tpl').replace('%s', messages['count']));
}
else {
control_group.removeClass('error').removeClass('info');
help_text.text('');
}
}
// show status and error messages
function updateUIMessages(data) {
updateSelector('parent', data[0]);
for (name in data[1])
updateSelector(name, data[1][name]);
['title', 'description', 'link'].forEach(function(name){
if (name in data[1])
updateSelector(name, data[1][name]);
else
updateSelector(name, {});
});
}
function updateUI(config) {
@ -103,6 +115,9 @@ function changed() {
function active() {
return _active;
}
function validate() {
return _validate;
}
window.ET = {
'showIcon': showIcon,
@ -111,7 +126,8 @@ window.ET = {
'updateUI': updateUI,
'updateUIMessages': updateUIMessages,
'getUIConfig': getUIConfig,
'active': active
'active': active,
'validate': validate
};
function show_ext(show) {
@ -137,6 +153,10 @@ $(document).ready(function(){
return true;
});
$("input[id^='ste-']").keyup(function(){
$("#check")[0].style.display = changed() ? 'inline-block' : 'none';
});
/*var cfg = read('xpathes')
if (cfg) {
updateUI(cfg);

View File

@ -60,14 +60,16 @@
<div id="st-extended" style="float:left; display:none">
<form class="form-horizontal">
<div class="control-group info">
<label class="control-label"><a href="{{ xpath_link }}" target="_blank">{% trans 'setup.item_xpath' %}</a>:</label>
<label class="control-label">
<a class="label label-info" href="{{ xpath_link }}" target="_blank">?</a>
{% trans 'setup.item_xpath' %}:</label>
<div class="controls">
<input type="text" id="ste-parent" placeholder="{% trans 'setup.skipped' %}" autocomplete="off"/>
<span class="help-inline" count-tpl="{% trans 'setup.Selected' %}"></span>
<input type="text" id="ste-parent" class="input-xxlarge" placeholder="{% trans 'setup.skipped' %}" autocomplete="off"/>
<span class="help-inline" count-tpl="{% trans 'setup.Selected' %}"></span>
</div>
</div>
<div class="control-group info">
<label class="control-label"><a href="{{ xpath_link }}" target="_blank">{% trans 'setup.title_xpath' %}</a>:</label>
<label class="control-label">{% trans 'setup.title_xpath' %}:</label>
<div class="controls">
<select disabled>
<option selected="selected">{% trans 'setup.Required' %}</option>
@ -78,7 +80,7 @@
</div>
</div>
<div class="control-group info">
<label class="control-label"><a href="{{ xpath_link }}" target="_blank">{% trans 'setup.link_xpath' %}</a>:</label>
<label class="control-label">{% trans 'setup.link_xpath' %}:</label>
<div class="controls">
<select style="width:100px" disabled>
<option>{% trans 'setup.Required' %}</option>
@ -89,7 +91,7 @@
</div>
</div>
<div class="control-group info">
<label class="control-label"><a href="{{ xpath_link }}" target="_blank">{% trans 'setup.description_xpath' %}</a>:</label>
<label class="control-label">{% trans 'setup.description_xpath' %}:</label>
<div class="controls">
<select style="width:100px" disabled>
<option selected="selected">{% trans 'setup.Required' %}</option>
@ -107,7 +109,8 @@
confirm-text="You may loose your changes. Are you shure?"><img src="{% static 'frontend/images/target48.png' %}" /></a>
<a id="st-ext-trigger" href="javascript:void(0)" style="display:none" class="has-tooltip" title="{% trans 'setup.extended_tip' %}"
data-trigger="hover focus manual" data-animation="true"><img src="{% static 'frontend/images/wrench48.png' %}" /></a>
<button id="create" class="btn btn-large btn-primary disabled" style="" data-page-url="{{ page_url }}" data-feed-page-url="{{ feed_page_url }}">{% trans 'setup.create' %} <i class="icon-arrow-right icon-white" style="margin-top: 3px"></i></button>
<button id="check" class="btn btn-large btn-primary" style="display:none">{% trans 'setup.check' %} <i class="icon-check icon-white" style="margin-top: 3px"></i></button>
<button id="create" class="btn btn-large btn-primary disabled" data-page-url="{{ page_url }}" data-feed-page-url="{{ feed_page_url }}">{% trans 'setup.create' %} <i class="icon-arrow-right icon-white" style="margin-top: 3px"></i></button>
</div>

View File

@ -88,7 +88,11 @@ def setup_get_selected_ids(request):
return HttpResponse(json.dumps(resp))
def _get_link_xpath(title_xpath):
return '('+ title_xpath +')[1]/ancestor-or-self::node()[name()="a"]/@href'
if title_xpath == './child::node()':
return './ancestor-or-self::node()[name()="a"]/@href'
else:
xpath = title_xpath[:len(title_xpath)-len('/child::node()')]
return xpath +'/ancestor-or-self::node()/@href'
def _create_feed(url, xpathes):
feed_xpath = xpathes[0]