Skip to content

Commit

Permalink
cc
Browse files Browse the repository at this point in the history
  • Loading branch information
jessec committed Oct 22, 2014
1 parent 8711d3d commit eb1dc83
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 137 deletions.
File renamed without changes.
158 changes: 21 additions & 137 deletions smallphoto/steps/step-1.js
Original file line number Diff line number Diff line change
@@ -1,144 +1,28 @@
function init(step) {

var parser = document.createElement('a');
parser.href = Wizard.config.pageUrl;
console.log(parser);

var dataRequest = Wizard.config.baseUrl + 'site/data.json?page='
+ parser.pathname + '&' + location.hash.substring(1);// 'edit-block-0-type-icon';

promise.get(dataRequest).then(function(error, text, xhr) {
if (error) {
// /alert('Error ' + xhr.status);
//return;
dataRequest = "";
}else{
console.log("result block data json : " + text);
var json = JSON.parse(text);
var config = {
data : 'site/blocks/block-video/smallphoto/data/smallphoto.json',
schema : {
type : "object",
title : "Photo",
"properties" : {
"photourl" : {
"type" : "url"
},
"content" : {
"type": "string",
"format": "html",
"options": {
"wysiwyg": true
}
}
}
}
getData(dataRequest);
});

console.log(Wizard.config.pageUrl + location.hash);
function getData(dataRequest) {

var req = dataRequest;
if(req == ""){
req = Wizard.config.baseUrl + 'site/blocks/block-video/smallphoto/data/basic.json';
}
promise
.get(req)
.then(
function(error, text, xhr) {
if (error) {
alert('Error ' + xhr.status);
return;
}

var starting_value = "";
try{
starting_value = JSON.parse(text).data;
}catch(e){}


if(typeof(starting_value) == "undefined" || starting_value == ""){
starting_value = JSON.parse(text);
}
// Initialize the editor
var editor = new JSONEditor(document
.getElementById('editor_holder-' + step), {
// Enable fetching schemas via ajax
ajax : true,
// The schema for the editor
schema : {
type : "object",
title : "Photo",
"properties" : {
"photourl" : {
"type" : "url"
},
"content" : {
"type": "string",
"format": "html",
"options": {
"wysiwyg": true
}
}
}
},
// Seed the form with a starting value
startval : starting_value,
// Disable additional properties
no_additional_properties : true,
disable_edit_json : true,
disable_properties : true,
disable_collapse : true,
// Require all properties by default
required_by_default : true
});
// Hook up the submit button to log to the console
document
.getElementById('submit-' + step)
.addEventListener(
'click',
function(event) {
event.stopPropagation();
console.log(editor.validate());
Wizard.goToNextStep(event);
console
.log('sending to swagger api');
console.log(editor.getValue());
}

var hash = location.hash
.split('=');
var data = hash[1].split('-');
var meta = {
"absolute-url" : document
.getElementById(
'iframe')
.getAttribute('src'),
"state" : data[0],
"block" : data[2],
"type" : data[4],
"template" : Wizard.widgetJson[data[4]].template
}
console.log(meta);

var fullData = {
"meta" : meta,
"editor" : editor
.getValue(),
}

var jsonString = JSON
.stringify(fullData);

var data = {
"id" : 112,
"data" : jsonString
};

promise
.post(
location.origin +'/api/block',
data)
.then(
function(error,
text,
xhr) {
if (error) {
alert('Error '
+ xhr.status);
return;
}
console
.log(text);
document
.getElementById('iframe').contentWindow.location = location.href;
});

});
function init(step) {

});
}
}
Wizard.run(step, config);
}

0 comments on commit eb1dc83

Please sign in to comment.