}
+__PACKAGE__->register_method(
+ method => "clone_distrib_form",
+ api_name => "open-ils.acq.distribution_formula.clone",
+ stream => 1,
+ signature => {
+ desc => q/Clone a distribution formula/,
+ params => [
+ {desc => "Authentication token", type => "string"},
+ {desc => "Original formula ID", type => 'integer'},
+ {desc => "Name of new formula", type => 'string'},
+ ],
+ return => {desc => "ID of newly created formula"}
+ }
+);
+
+sub clone_distrib_form {
+ my($self, $client, $auth, $form_id, $new_name) = @_;
+
+ my $e = new_editor("xact"=> 1, "authtoken" => $auth);
+ return $e->die_event unless $e->checkauth;
+
+ my $old_form = $e->retrieve_acq_distribution_formula($form_id) or return $e->die_event;
+ return $e->die_event unless $e->allowed('ADMIN_ACQ_DISTRIB_FORMULA', $old_form->owner);
+
+ my $new_form = Fieldmapper::acq::distribution_formula->new;
+
+ $new_form->owner($old_form->owner);
+ $new_form->name($new_name);
+ $e->create_acq_distribution_formula($new_form) or return $e->die_event;
+
+ my $entries = $e->search_acq_distribution_formula_entry({formula => $form_id});
+ for my $entry (@$entries) {
+ my $new_entry = Fieldmapper::acq::distribution_formula_entry->new;
+ $new_entry->$_($entry->$_()) for $entry->real_fields;
+ $new_entry->formula($new_form->id);
+ $new_entry->clear_id;
+ $e->create_acq_distribution_formula_entry($new_entry) or return $e->die_event;
+ }
+
+ $e->commit;
+ return $new_form->id;
+}
+
1;
+
--- /dev/null
+dimple.png derived from:
+http://mxr.mozilla.org/mozilla-central/source/toolkit/themes/pinstripe/global/splitter/dimple.png
+Mozilla Public License/GPL/GLPL
"SURVEY_QUESTION": "Question:",
"SURVEY_ID": "Survey ID # ${0}",
"SURVEY_FOOT_LABEL": "Questions & Answers",
- "EVENT_DEF_LABEL" : "${0}: ${1}"
+ "EVENT_DEF_LABEL" : "${0}: ${1}",
+ "ACQ_DISTRIB_FORMULA_NAME_PROMPT" : "Enter new formula name",
+ "ACQ_DISTRIB_FORMULA_NAME_CLONE" : "${0} (Clone)"
}
dojo.require('dijit.form.FilteringSelect');
dojo.require('openils.PermaCrud');
dojo.require('openils.widget.AutoFieldWidget');
+dojo.requireLocalization('openils.conify', 'conify');
+var localeStrings = dojo.i18n.getLocalization('openils.conify', 'conify');
+
var formCache = [];
var formula, entryTbody, entryTemplate, dndSource;
}
}
+
+function cloneSelectedFormula() {
+ var item = fListGrid.getSelectedItems()[0];
+ if(!item) return;
+ var formula = new fieldmapper.acqf().fromStoreItem(item);
+ fieldmapper.standardRequest(
+ ['open-ils.acq', 'open-ils.acq.distribution_formula.clone'],
+ {
+ asnyc : true,
+ params : [
+ openils.User.authtoken,
+ formula.id(),
+ dojo.string.substitute(localeStrings.ACQ_DISTRIB_FORMULA_NAME_CLONE, [formula.name()])
+ ],
+ oncomplete : function(r) {
+ if(r = openils.Util.readResponse(r)) {
+ location.href = oilsBasePath + '/conify/global/acq/distribution_formula/' + r;
+ }
+ }
+ }
+ );
+}
+
openils.Util.addOnLoad(draw);
function getItemCount(rowIndex, item) {
formula.entries(entries);
dojo.byId('formula_head').innerHTML = formula.name();
+ dojo.byId('formula_head').onclick = function() {
+ var name = prompt(localeStrings.ACQ_DISTRIB_FORMULA_NAME_PROMPT, formula.name());
+ if(name && name != formula.name()) {
+ formula.name(name);
+ pcrud = new openils.PermaCrud();
+ pcrud.update(formula);
+ dojo.byId('formula_head').innerHTML = name;
+ }
+ }
+
dojo.forEach(entries, function(entry) { addEntry(entry); } );
}
[% WRAPPER default/base.tt2 %]
[% ctx.page_title = 'Distribution Formulas' %]
<script type="text/javascript" src='[% ctx.media_prefix %]/js/ui/default/conify/global/acq/distribution_formula.js'></script>
-<script type="text/javascript"> var formulaId = '[% ctx.page_args.0 %]';
-function getFormulaName(rowIndex, item) {
- if(!item) return '';
- var name = this.grid.store.getValue(item, 'name');
- var id = this.grid.store.getValue(item, 'id');
- return id + ':' + name;
-}
+<script type="text/javascript">
+ var formulaId = '[% ctx.page_args.0 %]';
-function formatName(value) {
- if(value) {
- var vals = value.split(/:/);
- return '<a href="'+location.href+ '/'+vals[0]+'">'+vals[1]+'</a>';
+ function getFormulaName(rowIndex, item) {
+ if(!item) return '';
+ var name = this.grid.store.getValue(item, 'name');
+ var id = this.grid.store.getValue(item, 'id');
+ return id + ':' + name;
}
-}
+ function formatName(value) {
+ if(value) {
+ var vals = value.split(/:/);
+ return '<a href="'+location.href+ '/'+vals[0]+'">'+vals[1]+'</a>';
+ }
+ }
</script>
<div>
<button dojoType='dijit.form.Button' onClick='fListGrid.showCreateDialog()'>New Formula</button>
<button dojoType='dijit.form.Button' onClick='fListGrid.deleteSelected()'>Delete Selected</button>
+ <button dojoType='dijit.form.Button' onClick='cloneSelectedFormula()'>Clone Selected</button>
</div>
</div>
<table jsId="fListGrid"
<div id='formula-entry-div'>
<div dojoType="dijit.layout.ContentPane" layoutAlign="client" class='oils-header-panel'>
- <div id="formula_head"></div>
+ <div><a href='javascript:void(0);' id="formula_head"></a></div>
<div>
</div>
</div>
<td><div name='location'></td>
<td><div name='item_count'></td>
<td>
- <!-- TODO: add to repo / use local images -->
- <img src='http://mxr.mozilla.org/mozilla-central/source/toolkit/themes/pinstripe/global/splitter/dimple.png?raw=1'/>
- <img src='http://mxr.mozilla.org/mozilla-central/source/toolkit/themes/pinstripe/global/splitter/dimple.png?raw=1'/>
- <img src='http://mxr.mozilla.org/mozilla-central/source/toolkit/themes/pinstripe/global/splitter/dimple.png?raw=1'/>
+ <img src='[% ctx.media_prefix %]/images/dimple.png'/>
+ <img src='[% ctx.media_prefix %]/images/dimple.png'/>
+ <img src='[% ctx.media_prefix %]/images/dimple.png'/>
<td>
</tr>
</tbody>
</table>
-</div>
-<br/>
-<div>
- <button dojoType='dijit.form.Button' onClick='addEntry()'>New Entry</button>
- <span style='padding-right:20px;'></span>
- <button dojoType='dijit.form.Button' onClick='saveFormula()'>Apply Changes</button>
+ <br/>
+ <div>
+ <button dojoType='dijit.form.Button' onClick='addEntry()'>New Entry</button>
+ <span style='padding-right:20px;'></span>
+ <button dojoType='dijit.form.Button' onClick='saveFormula()'>Apply Changes</button>
+ </div>
</div>
[% END %]